Web Hosting Talk







View Full Version : passing one variable from one script to another


nethosting
08-24-2002, 04:32 PM
with the first script, it "suppose" to set the variable, and echo it. it does echo it back to me, so that tells me the problem is in the 2nd script. here is the code in the first script: <?php session_start(); $mysession = $HTTP_REFERER; session_register("mysession"); echo $HTTP_SESSION_VARS['mysession']; ?> second script: <?php session_start(); $tryit = $HTTP_SESSION_VARS['mysession']; ?>


any ideas?

SynHost
08-24-2002, 05:32 PM
If you registered the session variable, you don't have to use $HTTP_SESSION_VARS to call it. Just call it like a normal variable. The second script should have this code:

<?
session_start();
echo $mysession;
?>


You can just use the registered $mysession variable like it was a normal variable (cuz it is).

Hope this helps!

Ben Hughes
SynHost

Studio64
08-24-2002, 06:31 PM
Originally posted by SynHost

<?
session_start();
echo $mysession;
?>



Just remember the one catch with session vars is that; That line of code must be the VERY FIRST thing in the script. The session must be registered before anything else is sent to the browser on every script the variable is needed.

combs
08-25-2002, 10:36 AM
Righto!!!

Ahmad
08-25-2002, 10:29 PM
Originally posted by SynHost
If you registered the session variable, you don't have to use $HTTP_SESSION_VARS to call it. Just call it like a normal variable. The second script should have this code:

<?
session_start();
echo $mysession;
?>


You can just use the registered $mysession variable like it was a normal variable (cuz it is).

Hope this helps!

Ben Hughes
SynHost

This is not true if register_globals is off, which is the default for PHP 4.2 and above. Besides, it is not a good practice, security-wise.

SynHost
12-11-2002, 09:10 AM
Just remember the one catch with session vars is that; That line of code must be the VERY FIRST thing in the script. The session must be registered before anything else is sent to the browser on every script the variable is needed.

It doesn't have to be the very first thing, it just has to be in there before anything is sent to the browser... You could have 1000 lines of code before that and have it still work if nothing was sent to the browser.