登录后将页面重定向回index.php
我遇到的问题是,在我登录之后,它会返回index.php,并且必须再次登录。我应该看到注销按钮,而不是登录按钮。关于customerindex.php,它实际上并不存在,但我创建了该页面,以便可以看到“注销”按钮(并实际注销)。我计划删除customerindex.php,而只使用index.php validate2.php登录后将页面重定向回index.php,php,html,login,Php,Html,Login,我遇到的问题是,在我登录之后,它会返回index.php,并且必须再次登录。我应该看到注销按钮,而不是登录按钮。关于customerindex.php,它实际上并不存在,但我创建了该页面,以便可以看到“注销”按钮(并实际注销)。我计划删除customerindex.php,而只使用index.php validate2.php <?php include("connection.php"); //get data from login form $email = mysql_real_es
<?php include("connection.php");
//get data from login form
$email = mysql_real_escape_string($_POST["email"]);
$password = mysql_real_escape_string($_POST["password"]);
//select all data by using email and password entered
$customers = mysql_query("select * from customer where CustomerEmail='".$email."' and CustomerPassword='".$password."'");
$customer = mysql_num_rows($customers);
$managers = mysql_query("select * from manager where ManagerEmail='".$email."' and ManagerPassword='".$password."'");
$manager = mysql_num_rows($managers);
//if customer is true
if($customer== 1){
$row = mysql_fetch_assoc($customers);
$email = $row['CustomerEmail'];
$name = $row['CustomerName'];
//start session
session_start();
//create session
$_SESSION['CustomerEmail'] = $email;
$_SESSION['CustomerName'] = $name;
//redirect page to customerindex.php
header("Location: customerindex.php");
}
//if manager is true
else if($manager == 1){
$row = mysql_fetch_assoc($managers);
$email = $row['ManagerEmail'];
$name = $row['ManagerName'];
//start session
session_start();
//create session
$_SESSION['ManagerEmail'] = $email;
$_SESSION['ManagerName'] = $name;
//redirect page to managerCP.php
header("Location: managercp.php");
}
//if both condition are false
else {
//alert will be appeared
header("Location: index.php?login=Wrong username or password");
}
?>
在标题后添加退出。如下所示
header("Location: index.php");
exit;
使用。/
而不是index.php重定向到index.php
<div class="tab">
<ul class="login">
<li class="left"> </li>
<li>Hello <?php echo $customername ?>!</li>
<li class="sep">|</li>
<li id="toggle">
<a href="logout.php">Log Out</a>
</li>
<li class="right"> </li>
</ul>
</div> <!-- / top -->
更改此代码并查看它是否工作
你能链接文件logout.php
或描述你的工作吗?上面的php代码是validate2.php和logout.php吗?@AnotherGuy我刚刚编辑了我的帖子validate2.php
是处理登录的php文件,那么当你注销时,你正在删除一个不存在的会话变量。然后,如果您在其他地方进行了检查,以查看当前是否登录了该使用并对其进行重定向,则它们将被重定向回。这可以解释你的注销问题。另一件事。从validate2.php
中可以看到,您正在以纯文本形式存储密码。这是一个重大的安全问题。如果攻击者能够访问您的数据库,他将能够读取所有密码、用户名和电子邮件,并不仅在您的网站上使用它们,还可能在其他地方使用它们。添加退出不会起作用help@SameerShaikh你是对的,它不会解决问题,但是你应该在重定向后退出我同意,添加exit
在这里没有帮助,但停止不必要的代码执行(如果确实不必要的话)是一个很好的实践,但登录按钮仍然存在。用户登录@SameerShaikhbecause后应该看到logout按钮,因为当时使用头位置时,输出不应该在头位置之前启动,并且始终在头位置后添加exit,这样它将停止下一次代码执行。可以推断,问题不在错误的文件路径中,因为OP没有告诉我们任何有关404
错误的信息。否不起作用。卢卡是对的。html中缺少条件子句。我不知道在html中添加/编写什么,而且它应该被重定向回index.php,用户在成功登录后应该能够看到注销按钮。请帮帮我
<?php
session_start();
unset($_SESSION["email"]);
header("Location:index.php");
?>
header("Location: index.php");
exit;
if($customer == 1){
while($row = mysql_fetch_array($customers)){
$email = $row['CustomerEmail'];
$name = $row['CustomerName'];
}
//start session
session_start();
//create session
$_SESSION['CustomerEmail'] = $email;
$_SESSION['CustomerName'] = $name;
//redirect page to customerindex.php
header("Location: customerindex.php");
}
//if manager is true
else if($manager == 1){
while($row = mysql_fetch_array($managers)){
$email = $row['ManagerEmail'];
$name = $row['ManagerName'];
}
//start session
session_start();
//create session
$_SESSION['ManagerEmail'] = $email;
$_SESSION['ManagerName'] = $name;
//redirect page to managerCP.php
header("Location: managercp.php");
}
//if both condition are false
else {
//alert will be appeared
header("Location: index.php?login=Wrong username or password");
}