0
我正在学习如何创建一个登录页面,以了解有关会话工作方式的更多详细信息。我搜索了不同的网站,直到找到一个能够带来成功的网站。但是,成功登录后,我想设置用户可以在其中登录后点击其个人资料,编辑个人资料,帐户设置和注销的位置。注销没有问题,但没有显示配置文件的链接。使用会话登录PHP
下面是测试登录检查:
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> • (' . $_SESSION['lastlogin'] . ')
<a href="testuser_account.php">Account</a> •
<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)
正如你所看到的,我是想弄清楚我自己,所以我不会像我没有尝试。
参考
P.S:我看到其他的链接,但他们以不同的方式几乎让。令人困惑...
感谢任何人理解和抱歉,如果你不这样做。
第1步:停止使用mysql_并开始使用PDO或MSQLI –
警告:建议不要使用session_register()。该功能已弃用。请使用$ _SESSION全局变量来存储会话变量。 – arijeet
因此,将session_register('email')更改为$ _SESSION ['email']? – taeja87