我无法将登录会话信息传递给其他 HTML 页面。下面是我的登录 php 代码。我可以成功登录,但无法将信息传递到 HTML 主页等其他页面,尽管我没有登录,但它会被打开。我尝试了相同的不同代码
<?php
require_once("config.php");
$email=$_POST['email'];
$password=$_POST['password'];
$email = stripslashes($email);
$password = stripslashes($password);
$email = mysql_real_escape_string(strip_tags($email));
$password = mysql_real_escape_string(strip_tags($password));
// Check occurence of email password combination
$sql="SELECT * FROM register WHERE email='$email'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $email, table row must be 1 row
if($count==1)
{
$row = mysql_fetch_array($result);
if($password == $row['password'])
{
session_start();
$_SESSION['login'] = "1";
header("location:home.html");
exit;
}
else
{
echo "Please enter correct Password";
header("location:login.html");
session_start();
$_SESSION['login'] = ''
exit();
}
}
else
{
header("Location:register.html");
exit();
}
?>
Below is the php snippet that I use at the top of my HTML page:
<?php
require_once("config.php");
session_start();
if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {
header ("Location: login.html");
exit;
}
?>