Session handling in PHP5 Vs PHP4

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sanchan89
Forum Newbie
Posts: 3
Joined: Thu May 01, 2008 7:24 am

Session handling in PHP5 Vs PHP4

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Session handling in PHP5 Vs PHP4

Post 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
(#10850)
User avatar
lafever
Forum Commoner
Posts: 99
Joined: Sat Apr 05, 2008 2:03 pm
Location: Taylor, MI

Re: Session handling in PHP5 Vs PHP4

Post 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)
sanchan89
Forum Newbie
Posts: 3
Joined: Thu May 01, 2008 7:24 am

Re: Session handling in PHP5 Vs PHP4

Post 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????
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: Session handling in PHP5 Vs PHP4

Post by EverLearning »

Code: Select all

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