$_SESSION doesn't keep the ldap $link_identifier

我们两清 提交于 2019-12-24 10:47:07

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!