我有一个登录页面,它将一个变量发送到另一个页面,验证登录是真(1)还是假(0)。我可以在第1页上回显$ _SESSION ['logon']但是当我转到第2页时,我的会话似乎已经死了并且给了我*注意:未定义索引:登录*我已经摆弄了php.ini但无济于事。 Register_globals =顺便关闭。我是菜鸟,所以我可能错过了一些错误,没有更改php.ini中的正确参数,不知道。
登录页面:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="pt-br" xml:lang="pt-br">
<head>
<title>Alpha</title>
<link rel="stylesheet" href="CSS.css">
<script type="text/javascript" src="js/jquery-1.3.1.min.js"></script>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript" src="js/jquery.history.js"></script>
</head>
<body>
<form id="logbox" method="post" action="verylog.php">
User <input id="user" name="user" type="text" required/>
Password <input id="pass" name="pass" type="PASSWORD" required/>
<input id="send" type="submit"/>
</form>
<?php
if(isset($_POST['user'])){
header("Location: verylog.php");
}
?>
</body>
</html>
verylog.PHP“page1”
<?php
session_start();
$user=$_POST['user'];
$pass=$_POST['pass'];
$_SESSION['logon']=0;
$cost = ['cost' => 10,];
$hasheduser=password_hash($user, PASSWORD_BCRYPT,$cost);
$hashedpass=password_hash($pass, PASSWORD_BCRYPT,$cost);
$storeuserhash=file_get_contents('sunburn/userburn.txt');
$storepasshash=file_get_contents('sunburn/passburn.txt');
if(password_verify($user, $storeuserhash) && password_verify($pass, $storepasshash)){
session_regenerate_id(true);
$_SESSION['logon']=1;
header ("Location: ../sunburn/selector.php");
die();
//echo $_SESSION['logon'];
} else{
header ("Location: ../burnlogin.php");
die();
}
?>
selector.php“Page2”
<?php
session_start();
$logon=$_SESSION['logon'];
if($logon==0){
//header("Location: index.php");
exit();
echo $_SESSION['logon'];
}else{
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="pt-br" xml:lang="pt-br">
<head>
<link rel="stylesheet" href="localhost/CSS.css">
<link rel="stylesheet" href="CSS.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<div class="divreg">
<div>
<a href="../sunburn/register.php">
<button type="button" >-REGISTRAR-</button>
</a>
</div>
<div>
<a href="../sunburn/deltePAGE.php">
<button class="button1" type="button" value="deltePAGE" >-DELETAR-</button>
</a>
</div>
</div>
<div id="select">
</div>
</body>
<?php
}
?>
对于我可能发送的任何错字,我感到很抱歉。
答案 0 :(得分:3)
您在exit
之前使用echo
并且您需要检查pag2.php上的条件,如下所示:
if(isset($_SESSION['logon']) && $_SESSION['logon'] != "") {
$logon=$_SESSION['logon'];
if($logon==0){
//header("Location: index.php");
echo $_SESSION['logon'];
exit();
}
}