简体   繁体   English

PHP会话变量不跨页携带

[英]PHP session variables do not carry across pages

Hi I have created two session variables with the purpose of storing the list of ids of the query in a Comma-separated string to be broken apart into an array later. 嗨,我创建了两个会话变量,目的是将查询的ID列表存储在以逗号分隔的字符串中,以便稍后将其分解为一个数组。 The code works fine when I was running the code on localhost with apache; 当我使用apache在localhost上运行代码时,代码工作正常; however, when I upload the file on the actual server the $_SESSION variables declared in the main page never gets carried over to the second place. 但是,当我将文件上载到实际服务器上时,在主页中声明的$ _SESSION变量永远不会移到第二位。 I did an if statement on case.php page to test it, and I also did a var_dump() and they all showed NULL. 我在case.php页面上做了一个if语句来测试它,并且我也做了一个var_dump(),它们都显示为NULL。

I was wondering is there anything I need to configure with the server? 我想知道是否需要对服务器进行配置? As it reads PHP and does all other functions without any errors. 读取PHP并执行所有其他功能时,没有任何错误。 Appreciate any help or comments. 感谢任何帮助或评论。

Please see code below: 请参见下面的代码:

Main page: patients.php 主页: Patient.php

<?php 
// store session data 
session_start(); 
// store SQL line

// store patient ID
$_SESSION['pid']='';

// store case ID
$_SESSION['cid']='';


...
while ($record = mysql_fetch_row($result)) {

    $patient = $record[0];
    $statusD = $record[1];
    $substatusD = $record[2];
    $caseCount = $record[3];
    $statusReason = $record[4];
    $dateReviewed = $record[5];
    $caseID = $record[6];
    $lastUser =$record[7];  

    //statusFlagged($patient,$caseID,$dateReviewed);            
    $statusFlagged = $record[8];
    //StatusFlag should be working as of 5/30/2013. Please double check

    // comma-delimited patient ID
    $_SESSION['pid'].=$patient.',';

    // comma-delimited case ID
    $_SESSION['cid'].=$caseID.',';

Next Page: case.php 下一页: case.php

<?php 
// start session data 
session_start(); 
if(isset($_SESSION['pid'])) {
echo "Your session is running " . $_SESSION['pid'] . "and" . $_SESSION['cid'];
}
else { echo "Session not running";}

$patientIDString = $_SESSION['pid'];
$caseIDString = $_SESSION['cid'];
$patientIDArray = explode(',', $patientIDString);
$caseIDArray = explode(',', $caseIDString);

Thanks for the helpful suggestions. 感谢您的有用建议。 I found the solution by making sure that the path stored in session.save_path under php.ini is accessible. 我通过确保可访问php.ini下的session.save_path中的路径来找到解决方案。 Particularly if you are working with Apache. 特别是在使用Apache的情况下。 Need to make sure that the owner of the directory is the same as apache. 需要确保目录的所有者与apache相同。

After changing the path and the read/write access, everything works as it should. 更改路径和读/写访问权限后,一切都会正常进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM