PHP会话立即到期

时间:2013-08-27 04:01:19

标签: php mysql session

这是我的剧本:

我知道我只是通过电子邮件登录,而不是检查密码。这仅用于测试目的。

我成功登录,显示表单以搜索用户名。点击“验证帐户”链接后,我会丢失会话。如果我在登录后刷新页面,也会发生同样的情况。

为什么会这样?

<?php
$session_start;
mysql_connect ('localhost', 'root', '') ;
mysql_select_db ('findaduo');
if(isset($_POST['login'])) {
    $email = mysql_real_escape_string($_POST['email']);
    $password = mysql_real_escape_string($_POST['password']);
    $id = mysql_fetch_assoc(mysql_query("SELECT * FROM users WHERE email = '$email' "));
    $_SESSION['id'] = htmlspecialchars($id["id"]); 
}
?>
<html>
<body>
    <?php 
    if(isset($_SESSION['id'])) {
    echo 
        'Welcome back, ' . $id["username"] .
        '<form method="GET" action="profile.php">
            Search Username: <input type="text" name="username" /><br />
            <input type="submit" value="Submit" />
        </form><br />' 
        . 'Before you can search duos, you need to <a href="verify_leagueaccount.php">verify your account.</a>'
        ;
        $die;
    }
    else {
        echo '
            <form method="POST" action="index.php">
            <h4>Login</h4>
            <input type="text" name="email" placeholder="Email" /><br />
            <input type="password" name="password" placeholder="Password" /><br />
            <input type="submit" value="Login" name="login" /><br />
            </form>
            <a href="register.php">Register</a>
        ';
        $die;
    }
    //echo $id["id"];
    exit;
    ?>
</body>
</html>

1 个答案:

答案 0 :(得分:5)

session_start();而非$session_start;