这是一个登录表单,当用户名/密码与数据库值匹配时,我们会从该表单重定向到 login_success.php 页面。
检查登录.php
<?php
include 'config.php';
// username and password sent from form
$myusername=$_POST['email'];
$mypassword=$_POST['password'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM drsignup WHERE email='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION['email']=$myusername;
$_SESSION['password']=$mypassword;
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>
登录成功.php
此表单为登录和会话开始的用户显示欢迎消息。在下面的代码中,我无法使用欢迎字符串获取 $_SESSION['email'] 值并显示未定义的索引电子邮件。
我试图从 session_id() 收集 session_id;给出像 e9ubrn9v239o60tfalag6e6kt4 这样的值的函数。请让我知道为什么我无法在此处获取电子邮件 ID。如何将会话变量存储在我的所有 php 页面上。
<?php
session_start();
echo session_id();
SESSION_WRITE_CLOSE();
if(isset ($_SESSION['email']))
{
echo "Welcome $_SESSION['email']";
}
else
{
header("location:Drlogin.php");
}
?>