[英]Locking pages with session WITH redirect to login.php
I have a problem with locking the page with session AND I have to let it redirect to login.php if not logged in 我在使用会话锁定页面时遇到问题,如果未登录,我必须让它重定向到login.php
This is the script I have and I´ve tried many of them and somehow none of them works 这是我拥有的脚本,我尝试了许多脚本,但是它们都不起作用
<?PHP
include("include/session.php");
?>
<?PHP
if(isset($_SESSION['logged_in'])){
unset($_SESSION['logged_in']);
else
{
header ("location: login.php");
}
?>
<?PHP
if($session->logged_in){
?>
This code did worked at sometime but it didn´t redirect my to the login.php 这段代码在某个时候确实有效,但是没有将我重定向到login.php
This is the code on frontpage and every subpage where the page is locked so makeing attempt to access it should redirect to the login.php 这是首页和每个页面被锁定的子页面上的代码,因此尝试访问它应该重定向到login.php
Any suggestions? 有什么建议么?
Either there are quite a few things wrong with your code, or I misunderstand the question_ 您的代码有很多错误,或者我误解了问题
if(isset($_SESSION['logged_in'])){
ends with an unbalanced bracket if(isset($_SESSION['logged_in'])){
以不平衡的括号结尾 unset()
the logeed-in status, if you read it from the session? unset()
登录状态? if($session->logged_in)
the same as if(isset($_SESSION['logged_in']))
? if($session->logged_in)
与if(isset($_SESSION['logged_in']))
吗? Anyway, what I suggest is 无论如何,我建议的是
header ("location: login.php");
header ("location: login.php");
to header ("Location: login.php");
header ("Location: login.php");
, some browsers might be picky with the caps , ,
<?php
include("include/session.php");
if(isset($_SESSION['logged_in']))
{
?>
<!-- whatever you wanna do -->
<?php
}
else
{
header ("Location: login.php");
exit;
}
?>
And make absolutely sure, nothing (especially no line breaks or whitespace) are ouptut in include/session.php
并绝对确保,
include/session.php
没有任何内容(尤其是没有换行符或空格)
Make sure the login.php
is in path; 确保
login.php
在路径中; is it in the same folder? 在同一个文件夹中吗?
You should not have to unset the logged_in
. 您不必取消设置
logged_in
。
Anyway, if that does not solve it, post full session.php
and we shall look into it. 无论如何,如果仍然不能解决问题,请发布完整的
session.php
,我们将对其进行调查。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.