php会话不起作用 [英] php session doesn't work

查看:76
本文介绍了php会话不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应如何工作: Index.php是安全页面.它包括check.php,它检查您的会话是否良好.如果尚未登录,则说明您尚未登录->注销,然后删除会话.但是它不起作用,它总是注销,就像我没有登录...

How it should work: Index.php is the secured page. It includes check.php, which checks if you have a session = good. If it hasn't, you're not logged in -> log off, remove session. But it doesn't work, it always logs off, like I didn't log in...

index.php

include ‘check.php’;
echo "logged in";

check.php

session_start();
if($_SESSION[‘login’] != ‘good’) {
unset($_SESSION[‘login’]);
unset($_SESSION[‘name’]);
header(‘Location: login.php?logoff’);
exit();
} 

Login.php

if(isset($_POST[‘login’])) {
$gb = array();
$gb[‘user1’] = ‘pass1’;
$gb[‘user2’] = ‘pass2’;
if(isset($gb[$_POST[‘username’]]) && $gb[$_POST[‘username’]] == $_POST[‘password’])
{ 
$_SESSION[‘login’] = ‘good’;
$_SESSION[‘name’] = $_POST[‘name’];

header("Location: index.php");
} else {

header("Location: login.php?wrongpass");

}

} else { ?>
Login Form
<?php } ?>

我希望有人能帮助我!

推荐答案

您应该验证是否已在login.php中启动了会话.

You should verify you started the session in login.php.

这篇关于php会话不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆