我知道这个问题被多次询问,但没有一个解决方案适合我。
我可以设置会话但问题是,由于某种原因,当我的会话未设置时,它会一直说你的会话已设置。
这是我的代码:
session_start();
if($_SESSION["GOALOLD"]=="GOALOLDVALS") {
//echo $_SESSION['GOALOLD'];
$prog_descs = "";
$sel_prog_descs = "SELECT * FROM prog_description WHERE cons_id = '" . $_SESSION['behaviour_user'] . "' AND prog_id = '" . $_SESSION['prog_id'] . "' AND student_id = '" . $_SESSION['current_student'] . "' ORDER BY prog_desc_id DESC LIMIT 1";
$sel_prog_dessc = mysql_query($sel_prog_descs) or die(mysql_error());
if (mysql_num_rows($sel_prog_dessc) > 0) {
$rs_prog_dessc = mysql_fetch_array($sel_prog_dessc);
$prog_descs = $rs_prog_dessc['prog_goal_con'];
}echo $prog_descs;
}else if($_SESSION["GOALNEW"]=="GOALNEWVALS") {
//echo $_SESSION['GOALNEW'];
$prog_descs = "";
$sel_prog_descs = "SELECT * FROM prog_description WHERE cons_id = '" . $_SESSION['behaviour_user'] . "' AND prog_id = '" . $_SESSION['prog_id'] . "' AND student_id = '" . $_SESSION['current_student'] . "' ORDER BY prog_desc_id DESC LIMIT 1";
$sel_prog_dessc = mysql_query($sel_prog_descs) or die(mysql_error());
if (mysql_num_rows($sel_prog_dessc) > 0) {
$rs_prog_dessc = mysql_fetch_array($sel_prog_dessc);
$prog_descs = $rs_prog_dessc['prog_goal_con'];
}
echo $prog_descs;
}else{
}
以下是我解开会话的方式:
unset($_SESSION['GOALOLD']);
unset($_SESSION['GOALNEW']);
是否有可靠且正确的方法来检查会话,是否设置,或者是否有一些xyz值?
对我来说,他们没有工作。
我甚至尝试过在另一个浏览器中但仍然遇到同样的问题,它一直说它已设置。可能我的if else
有错误或有技术问题;我不确定。
答案 0 :(得分:0)
这里没有太多的“马车”。 $_SESSION
只是一个数组..
如果您在测试前var_dump($_SESSION)
,这可能会帮助您发现错误。
答案 1 :(得分:0)
首先,你必须要开始SESSION
<?php
$f_pointer=fopen("https://www.parsehub.com/api/v2/projects/tM9MwgKrh0c4b81WDT_4FkaC/ last_ready_run/data?api_key=tD3djFMGmyWmDUdcgmBVFCd3&format=csv","r");
while(! feof($f_pointer)){
$ar=fgetcsv($f_pointer);
echo $ar[1];
echo "<br>";
}
?>
答案 2 :(得分:0)
您可以像这样检查会话变量:
Array
(
[0] => Array
(
[permission_id] => 1
[role_id] => 1
)
[1] => Array
(
[permission_id] => 2
[role_id] => 1
)
[2] => Array
(
[permission_id] => 3
[role_id] => 1
)
[3] => Array
(
[permission_id] => 4
[role_id] => 1
)
)
DB::table('permission_role')->insert($permission)
确保在读取或写入会话数组之前调用session_start();
if(isset($_SESSION['GOALOLD']) && !empty($_SESSION['GOALOLD'])) {
//Put here here want you want when If session of GOALOLD is set
}
。