只是一个新手,所以请原谅我的错误。
我正在使用.shtml页面(SSI)的网站上工作。 我正在尝试在我的.shtml页面中包含一个PHP脚本。 到目前为止,一切工作正常: PHP脚本被包含在内,它完成了它的目的。 这里是实际的例子。 有主页(index.shtml),包括脚本调用security_check.php这个指令:当SHTML页面包含脚本时,PHP会话不工作
<!--#include virtual="includes/security_check.php?idOp=000&idPage=0000" -->
这是security_check.php PHP代码:
<?php
session_start();
include('config.php');
include('myfunctions.php');
include('security_functions.php');
$idOp = $_GET['idOp'];
$idPage = $_GET['idPage'];
$allowedReferer = array();
// Connection to the database (defined in myfunctions.php)
$link = DB_Connect($DBhost, $DBuser, $DBpass, 1, $DBname);
// Check if the PHP session already exists. If not, create one
// (that is insert a record in the DB and returns the id, which
// will be stored in the PHP session variable).
// user ID is 0 because not logged yet
if (!isset($_SESSION['idSess'])) {
$_SESSION['idUser'] = 0;
$_SESSION['idSess'] = create_session(); // security_functions.php
}
// Please note that create_session() correctly use $_SESSION['idUser']
// in order to do its work, even if it's not passed as a parameter
// (as it should be: $_SESSION is a superglobal!) and the same goes
// for activity_supervisor().
// Defined in security_functions.php:
// it uses both $_SESSION['idUser'] and $_SESSION['idSess']
activity_supervisor($idPage,$allowedReferer,2,$link);
mysql_close($link);
?>
在这点, 主页正确显示,并在其中有一个“注册”按钮 ,调用sign.shtml。 这sign.shtml页面包括非常相同 security_check.php脚本 完全相同的包括已经看到所不同的是idPage参数的值,在这种情况下是0001
指令我希望脚本识别PHP会话,因此 不是创建一个新的会话,但确实创建了一个新的会话每隔时间。
我已经阅读了所有其他与PHP会话相关的帖子不工作,我甚至尝试过那里提出的解决方案。
- 在session_start()是在每个脚本的顶部开始写,因为有只是一个脚本
- 的session.save_path等于到/ var/lib中/ PHP /会话,并且是可写的Web服务器
- 我已经尝试过设置session.gc_probability = 0并重新启动web服务器(无济于事,所以我回到session.gc_probability = 1)
- 我用不同的浏览器(即Firefox和Chrome)尝试了相同的结果
所以我尝试了下面的测试(注意session_start()之前的那两个空行):我总是用空间指令这种方式来提高可读性) cre阿婷一个简单的脚本test.php的
<?php
session_start();
if (!isset($_SESSION['foo'])) {
$_SESSION['foo'] = 1;
echo ('Value is '.$_SESSION['foo'].'<br/>');
echo ('<a href="test.php">Refresh</a>');
}
else {
$_SESSION['foo']++;
echo ('Value is '.$_SESSION['foo'].'<br/>');
echo ('<a href="test.php">Refresh</a>');
}
?>
好吧,不管你信不信,我每次打“刷新”, 是增加价值,所以PHP识别会话(在test.php的脚本里面与index.shtml和sign.shtml页面相同的域)。
我甚至试图让PHP脚本显示一个.html文件(不是.shtml)的链接,然后显示一个test.php链接。它工作正常!
当PHP脚本包含到.shtml页面时,即使看不到任何理由,它确实似乎没有正确设置会话。也许你知道为什么,首先是如何规避这种无聊的行为?它是一个功能吗?它取决于php.ini中的参数设置吗?
最后提示:
OS:CentOS的6.3 2.6.32-279.el6.x86_64内核
Server版本:阿帕奇/ 2.2。15(Unix)
PHP 5.3.3
服务器是我的,所以我可以配置一切,如果需要的话。
在此先感谢并原谅我发表了长篇文章:我试图使其明确表明PHP会话在我所知的其他任何情况下都能够完美地工作。
TL; DR但是...您是否知道您正在插入PHP脚本的**输出**,而不是其代码? –
如果您只是使用PHP包含而不是SSI作为会话脚本,那将会简单得多。 – Derek
您不能调用'session_start()'或任何需要使用mod_include(SSI)修改头文件的任何东西。将URL直接连接到PHP脚本或使用ESI。 – symcbean