-6

这是我的代码:

注意:未定义索引:第 36 行 C:\xampp\htdocs\3\header.php 中的 id 注意:未定义索引:第 47 行 C:\xampp\htdocs\3\header.php 中的 id

    <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>
4

2 回答 2

0

您会收到警告,因为$_SESSION['id']它是未定义的。我会怎么做,

在您的页面顶部我初始化一个变量$sessionid

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

那么支票就是这样

if(!empty($sessionid)){
 //do something
}
于 2013-10-02T18:46:20.477 回答
0
<?php if ($_SESSION['id'] != ""): ?>

应该

<?php if (isset($_SESSION['id']) && $_SESSION['id'] != ""): ?>
于 2013-10-02T18:42:20.753 回答