我创建了一个会话,但在“login.php”中输入电子邮件和密码后,页面再次重定向到“login.php”。以下代码是检查电子邮件和密码验证的“login.php”的下一页。
<?php
$con = mysql_connect("localhost","Rahul","");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("ebusiness", $con);
$result=mysql_query("select * from members where Email='$_POST[login]' and Password='$_POST[pwd]' ") or die(mysql_error());
while($row=mysql_fetch_array($result)) {
if(strcmp("trim($_POST[login])","trim($row[Email])"==0 ) && strcmp("trim($_POST[pwd])","trim($row[Password])")==0) {
echo "<meta http-equiv='refresh' content='0.5;url=home.php'/>";
session_start();
$_SESSION['email']=$_POST['login'];
$_SESSION['id']=$row['id'];
echo "<br><br><br>";
echo "<table align='center' border='0' cellspacing='0' cellpadding='0' bgcolor='#F0F0F0'><tr></tr><tr align='center'><td><h3>Please wait...</td></tr></table>";
return;
}
}
mysql_close($con);
?>
“home.php”页面是在成功验证后显示信息的页面。home.php 的代码:
<?php
session_start();
if (!isset($_SESSION['email'])) {
header("Location: login.php");
return;
} else {
$con = mysql_connect("localhost","Rahul","");
mysql_select_db("ebusiness", $con);
$result = mysql_query("SELECT * FROM members WHERE id = $_SESSION[id]") or die(mysql_error());
while($row = mysql_fetch_array($result)) {
echo "<table height=100% width=100% border='0' cellspacing='0'><tr height=20%><td colspan=2>";
include 'header.php';
echo "</td></tr>";
}
}
?>
会话首先在“welcome.php”上创建,然后在“home.php”上检查会话是否存在。然后它重定向到“login.php”。但是因为我已经创建了一个会话.. 我不明白为什么 home.php 没有加载。请帮助我..