Page 1 of 1

Session handling in PHP5 Vs PHP4

Posted: Thu May 01, 2008 7:33 am
by sanchan89

Code: Select all

<?php
       session_start();
?>
<HTML>
<BODY>
 
<?php
   $sess_var = 100;
   if(session_register(“sess_var”))
      echo "Its happening";
   else
        echo "You might as well SMC";
 
   echo "<br>". $sess_var ."<br>";
    echo "<br>". $_SESSION["sess_var"] ."<br>";
?>
</BODY>
</HTML>
 
This code gives the output as follows

Code: Select all

 
Its happening
100
 
 
As can be seen the $_SESSION["sess_var"] is not working at all.
$HTTP_SESSION_VARS also gives the same result. What could be the problem.

Also when I start the page, a warning appears saying that there could be an incompatibilty issue.

Code: Select all

 
Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0
 
:banghead:

Please help me out. I'm a newbie and am very interested to learn PHP.
Thanks a mega lot.

Re: Session handling in PHP5 Vs PHP4

Posted: Thu May 01, 2008 10:23 am
by Christopher
You should read through the section in the manual on Sessions.

http://www.php.net/manual/en/book.session.php

Specifically read things like the Notes in session_register()

http://www.php.net/manual/en/function.s ... gister.php

Re: Session handling in PHP5 Vs PHP4

Posted: Thu May 01, 2008 10:27 am
by lafever
Read the notes in the manual

http://hk2.php.net/session_register
If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered(), and session_unregister().
Looks like arborint beat me to it 8)

Re: Session handling in PHP5 Vs PHP4

Posted: Thu May 01, 2008 12:41 pm
by sanchan89
:banghead: :banghead: :banghead: :banghead: :banghead: :banghead: :banghead:
Punch me in the crotch and shoot me in the head

Even two hours after making the corrections you kind gentleman brought to my notice. The same problem was recurring.
The warning was gone but the session variables still could not be read properly.

Wanna know why???
$_SESSSION['whatever']
instead of
$_SESSION['whatever']
My God!!! Wouldn't there be a compiler or somethin that'd only be too glad to tell me that I'm an ass when I make such mistakes.
Finding out the hard way really sucks man!!
How's one supposed to find out mistakes like these????

Re: Session handling in PHP5 Vs PHP4

Posted: Thu May 01, 2008 1:37 pm
by EverLearning

Code: Select all

error_reporting(E_ALL); 
ini_set('display_errors', true);