[英]Header doesn't work in combination with session_start?
To avoid illegal use I check the login status at the beginning of the code. 为避免非法使用,我在代码开头检查登录状态。 I do this as follows:
我这样做如下:
if (!isset($_SESSION['loggedin'])){
header('Location:http://www.name.nl/prg/login.php');
exit();
}
This works. 这可行。 But if I use this code first it doesn't work.
但是,如果我先使用此代码,它将无法正常工作。
ini_set('session.save_path',realpath(dirname($_SERVER['DOCUMENT_ROOT'])).'/name.nl/tmp');
session_start();
if (!isset($_SESSION['loggedin'])){
header('Location:http://www.name.nl/prg/login.php');
exit();
}
Am I missing something? 我想念什么吗? I looked for 2 days now, but can't find a reason/solution.
我看了两天了,但找不到原因/解决方案。 It seems to me that the header function should work after ini_set and session_start.
在我看来,头函数应该在ini_set和session_start之后工作。 I mean it is common code?
我是说这是通用代码?
Try this first: ini_set('session.save_path',realpath(dirname($_SERVER['DOCUMENT_ROOT']).'/name.nl/tmp')); 首先尝试:ini_set('session.save_path',realpath(dirname($ _ SERVER ['DOCUMENT_ROOT'])。'/ name.nl/tmp'));
(Move parentheses) (移动括号)
Try looking here: http://php.net/manual/en/function.session-save-path.php 尝试在这里查看: http : //php.net/manual/en/function.session-save-path.php
Not sure if this will help or not but it seems related to where your session folder is at and then pointing to the proper directory/folder in your code. 不确定这是否有帮助,但似乎与会话文件夹所在的位置有关,然后指向代码中正确的目录/文件夹。
The solution that worked for them: ini_set('session.save_path',realpath(dirname($_SERVER['DOCUMENT_ROOT']) . '/../session')); 适用于他们的解决方案:ini_set('session.save_path',realpath(dirname($ _ SERVER ['DOCUMENT_ROOT'])。'/../session'));
Your current session save: 您当前的会话保存:
ini_set('session.save_path',realpath(dirname($_SERVER['DOCUMENT_ROOT'])).'/name.nl/tmp'); 函数ini_set( '的session.save_path',真实路径(目录名($ _ SERVER [ 'DOCUMENT_ROOT'])) '/ name.nl/tmp');
Well I found the cause. 好吧,我找到了原因。 I had an "echo statement" before the header statement.
我在标题语句之前有一个“ echo语句”。 After deleting this statement it works fine.
删除此语句后,它可以正常工作。 Thx for your comment anyway!
谢谢您的评论!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.