2013-10-02 156 views
-6

這裏是我的代碼:我的代碼有什麼問題? 9

說明:未定義指數:ID在C:\ XAMPP \ htdocs中\ 3 \的header.php在線路36上 說明:未定義指數:ID在C:\ XAMPP \ htdocs中\ 3 \上線47

<tr> 
     <td> 
       <table align=center> 
       <tr align=center> 
         <td><a href="index.php">Ask</a> | </td> 
         <td><a href="search.php">Questions</a> | </td> 
         <?php if ($_SESSION['id'] == ""): ?> 
         <td><a href="login.php">Login</a> | </td> 
         <td><a href="register.php">Register</a></td> 
         <?php else: ?> 
         <td><a href="expdir.php">Expert Directory</a> | </td> 
         <td><a href="logout.php">Logout</a> </td> 
         <?php endif; ?> 
       </tr> 
       </table> 
       <table align=center> 
       <tr align=center> 
        <?php if ($_SESSION['id'] != ""): ?> 
         <td><a href="cpanel.php">My Control Panel</a> | </td> 
         <td><a href="search.php?id=<?php echo $_SESSION['id']; ?> 
">My Questions</a> | </td> 
         <?php if ($_SESSION['type'] == 'expert'): ?> 
           <td><a href="feedback.php">Feedback</a> | </td> 
         <?php endif; ?> 
         <td><a href="pm_inbox.php">Private Messenger</a> | </td> 
         <td><a href="reports.php?action=Accepted">Reports</a> | </td> 
         <td><a href="contact.php?action=Accepted">Contact</a> </td> 
        <?php endif; ?> 
       </tr> 
       </table> 
     </td> 
</tr> 
+0

'$ _SESSION [「身份證」] '它是未定義的 –

+0

你還應該確保你在訪問'$ _SESSION'超級全局之前調用'session_start()'。我建議閱讀php中的會話處理:http://www.php.net/manual/en/intro.session.php –

回答

0
<?php if ($_SESSION['id'] != ""): ?> 

的header.php應該

<?php if (isset($_SESSION['id']) && $_SESSION['id'] != ""): ?> 
+0

或'<?php if(!empty($ _ SESSION ['id'])) :?>' –

0

你得到的警告,因爲$_SESSION['id']它是不確定的。我該怎麼做,

在你的頁面頂部我初始化變量$sessionid

$sessionid = (isset($_SESSION['id']) ? $_SESSION['id'] : NULL; 

然後檢查會以這種方式

if(!empty($sessionid)){ 
//do something 
}