Forum Moderators: coopster

Message Too Old, No Replies

Getting mad with $_SESSION

Refuse to register my session

         

tomda

9:50 am on Apr 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Spent the all morning trying to understand why?
I am usually good to debug but this time, I am lost!

if(isset($_SERVER["HTTP_REFERER"])) {
session_register("backurl"); $_SESSION["backurl"]=$_SERVER["HTTP_REFERER"];
//session_register("try"); $_SESSION["try"]="TRY";
}

The code itself is pretty easy.
When remove the // of the second line, $_SESSION["try"] is registered and appear in my session file. So what can be wrong with the $_SESSION["backurl "] knowing that:

The $_SESSION["backurl"] is in fact registered (since echo $_SESSION["backurl"] give me what I want), it is just that when I am trying to see its value in the session file, I DON'T SEE IT!

omoutop

10:28 am on Apr 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



if(isset($_SERVER["HTTP_REFERER"]))
{
session_register("backurl");
$_SESSION["backurl"]=$_SERVER['HTTP_REFERER'];
session_register("try");
$_SESSION["try"]="TRY";
}

havent change nothing.... works fine to me

tomda

10:54 am on Apr 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks omoutop, yes the code is fine.

I have not found the problem yet, but still looking and making progress. Very very strange behaviour though.

1/ I have an include called "kill_back_session.php" that session_unregister("backurl"). When removing this line, "BACKURL" appear in my session file. My conclusion is that the include is called somewhere in my PHP webpage and unregistering the session.

2/ I have added echo $_SESSION["backurl"] at the end of the page and it works fine, so if the include is called it is not in the page?

3/ I have added some text in the include to find out where it is called and see nothing.

How can it be? Really strange!

tomda

11:11 am on Apr 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just to confirm that strangely my include file called "kill_back_session.php" is indeed the one unregistering the session AND THIS DESPITE THE FACT it is not called!

tomda

11:58 am on Apr 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I just give up... Tired of wasting my time, I think I'll delete the include.

The include looks like this

<?php
echo 'text<br>text<br>text<br>text<br>text';
//echo 'de
session_register("try"); $_SESSION["try"]="HELP";
?>

1/ The include is never called but $_SESSION["try"] is still set.
2/ I do not see any text (1st line).
3/ When removing the // (2nd line), it should give an error message, but it doesn't and $_SESSION["try"] is not set.

It become ridiculous!
Nice WE

coopster

12:05 pm on Apr 7, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I can't see anything wrong here either but if you are unregistering it that may be the source of the problem. Why are you using register/unregister anyway?


If you want your script to work regardless of register_globals, you need to instead use the $_SESSION array as $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where the PHP directive register_globals is disabled.

And we all know how we should be treating register_globals [php.net], correct?

session_register [php.net]

tomda

12:27 pm on Apr 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And we all know how we should be treating register_globals, correct?

Correct Coopster. Thank you for spotting the mistake.
I'll stick to $_SESSION for now.