if(!isset($_SESSION['SessData'])) {
session_name('sess1');
session_start();
echo '----- In IF Condition -----';
print_r($_SESSION['SessData']['Tracker']['Source']);
}
else {
echo '----- In ELSE Condition -----';
print_r($_SESSION['SessData']['Tracker']['Source']);
}
执行代码时,它只在IF条件而不是else条件下运行。是什么背后的原因?
答案 0 :(得分:0)
工作代码如下:
if(phpversion() < '5.4.0') {
if(session_id() == '') {
session_name('sess1');
session_start();
echo 'here1';
}
else {}
}
else if(phpversion() >= '5.4.0') {
if(session_status() == PHP_SESSION_NONE) {
session_name('sess1');
session_start();
echo 'here2';
}
else {}
}
if(!isset($_SESSION['SessData'])) {
echo '----- In IF Condition -----';
print_r($_SESSION['SessData']['Tracker']['Source']);
echo '<br />';
echo session_id();
}
else {
echo '----- In ELSE Condition -----';
print_r($_SESSION['SessData']['Tracker']['Source']);
echo '<br />';
echo session_id();
}