0

我正在学习如何制作登录页面,在那里我了解了有关会话如何工作的更多详细信息。我搜索了不同的站点,直到找到一个成功的站点。但是,在成功登录后,我想设置用户可以单击其个人资料、编辑个人资料、帐户设置和登录后注销的位置。注销没有问题,但没有显示个人资料的链接。

这是测试登录检查:

ob_start();  
// To protect MySQL injection (more detail about MySQL injection)
$email = stripslashes($email);
$password = stripslashes($password);
$email = mysql_real_escape_string($email);
$password = mysql_real_escape_string($password);

$sql="SELECT * FROM users WHERE email='$email' and password='$password'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

// If result matched $username and $password, table row must be 1 row
if($count==1){

// Register $username, $password and redirect to file "login_success.php"
session_register('email');
session_register('password');
session_register('userID'); // Tried and didn't work
session_register('lastlogin'); // Tried and didn't work

ob_end_flush();

这是在主页上

session_start(); 

// See if they are a logged in member by checking Session data
$userlinks = "";

if (isset($_SESSION['email'])) {
    // Put stored session variables into local php variable
    $userID = $_SESSION['userID'];
    $username = $_SESSION['username'];
    $lastlogin = $_SESSION['lastlogin'];

    //If session is successful, the following is available: profile, last login,    account and logout.
    $userlinks = '
    <a href="testuser.php?userID=' . $_SESSION['userID'] . '">' . $_SESSION['email'] . '</a> &bull; (' . $_SESSION['lastlogin'] . ') 
    <a href="testuser_account.php">Account</a> &bull; 
    <a href="testlogout.php">Log Out</a>';
} else {
    // If session failed, see if the user has a Damju account.
    $userlinks = 'Have an account? <a href="testlogin.php">Click Here</a> <br/> Not registered? <a href="testreg.php">Click Here</a>';
}

这就是我想要的: (a href="testuser.php?userID=#")username(/a)

正如你所看到的,我试图弄清楚自己,所以我不会看起来我没有尝试。

参考

PS:我查看了其他链接,但它们几乎是以不同的方式制作的。令人困惑...

感谢任何理解和抱歉的人,如果你不这样做。

4

1 回答 1

0

使用设置用户 ID

$_SESSION['userid'] = $userid;

只要您的会话在每个页面上启动,您就可以从任何地方访问会话变量

session_start();

使用

$_SESSION['userid'];

例如

$userid= $_SESSION['userid'];
echo $_SESSION['userid'];

如果您甚至想查看会话中的内容,只需执行

print_r($_SESSION);

当您的用户注销时,请确保您取消设置变量然后销毁会话

unset($_SESSION['userid']);
session_destroy();
于 2012-05-28T16:34:16.970 回答