1

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.

G4schberle
  • 25
  • 1
  • 4

1 Answers1

0

You cannot store Resource in storage, because session data is serialized before save. Read this http://php.net/manual/en/function.serialize.php

ponury-kostek
  • 7,824
  • 4
  • 23
  • 31
  • First of all thanks for the fast help. Second: Indeed! Thats the problem. But is there a workaround to carry over the 'ldap link' Ressource to another page? – G4schberle Feb 22 '17 at 11:31
  • Unfortunately no, because all resources are destroyed at script execution end. – ponury-kostek Feb 22 '17 at 11:39