如何启动会话并销毁会话,然后再次启动新会话并销毁PHP?

时间:2018-10-27 11:24:14

标签: javascript php

在我的代码中,错误和error1正常工作,但在error2时未显示。根据用户对待电子邮件和密码框的方式,错误,错误1和错误2必须显示在同一位置。而且error2必须以绿色显示。

login.php

$email = $_POST['email'];
$password = $_POST['password'];
if($email!=''&&$password!='')
{
$q = "select * from user where uemail='$email' and password='$password'";
$result = mysqli_query($con, $q);
$num = mysqli_num_rows($result);
if($num == 1){
Header( 'Location: home.php');
exit;
}else{
$_SESSION['error']= "Incorrect email or password!";
$_SESSION['error1']= "Try again later!";
Header( 'Location: index.php');
exit;
}
}else{
$_SESSION['error2']= "Please enter in box";
Header( 'Location: index.php');
exit;
}

index.php

<?php
session_start();
if(isset($_SESSION['error'])){
echo '<div  id="display">' . $_SESSION['error'] .  '</div><script 
type="text/javascript">  
function showIt() {  
document.getElementById("display").style.visibility = "hidden";  
}  
setTimeout("showIt()", 3000); 
function showIt() {
    document.getElementById("display").style.cssText = "color: green";
    document.getElementById("dislpay").style.visibility = "visible";
    document.getElementById("dislpay").innerHTML = "'.$_SESSION["error1"].'";
}
</script>';
}
unset ($_SESSION['error1']);
unset ($_SESSION['error']); 
session_destroy ();
?>
<?php
session_start();
if(isset($_SESSION['error2'])){
echo '<div  id="display">' . $_SESSION['error2'] .  '</div>';
}
unset ($_SESSION['error2']); 
session_destroy ();
?>

1 个答案:

答案 0 :(得分:0)

您的代码看起来正确,但是您必须在每个页面上初始化session_start()