问题
I encountered a strange behaviour of the session variable when storing the ldap link identifier to it. For that I have created two php snippets.
test1.php:
<?php
session_start();
$_SESSION['test']=ldap_connect('ldap://asc-OpenLDAP.asc.asc-syscon.de');
echo $_SESSION['test'];
?>
Output: Resource id #2
So far everything is nice and fine. But then when I try to use $_SESSION on the second page it suddenly holds a wrong value.
test1.php:
<?php
session_start();
$_SESSION['test']=ldap_connect('ldap://asc-OpenLDAP.asc.asc-syscon.de');
header('Location:test2.php');
?>
test2.php:
<?php
session_start();
echo $_SESSION['test'];
?>
Output: 0
Why is that so? How can I make it keep the correct value from test1.php?
Looking forward to your help.
回答1:
You cannot store Resource
in storage, because session data is serialized before save. Read this http://php.net/manual/en/function.serialize.php
来源:https://stackoverflow.com/questions/42388191/session-doesnt-keep-the-ldap-link-identifier