Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Session Variables From One Script to Another

Status
Not open for further replies.

jmg498

Technical User
Oct 31, 2007
26
0
0
US
The hosting service I am using does not permit the use of registering globals. But I need to pass a variable with a constant value to other scripts that are called.

I've tried:

Code:
<?php
session_start();
$location = $_GET['location'] // Passed in from a webform.
session_register("location");
?>

But the value of $location does not appear in the other scripts. I'm also not sure if I'm calling it correctly from the other scripts. I do have session_start(); at the beginning of the other scripts.

Any ideas? Thanks much!

 
Code:
<?php
// Assign form variable to session
session_start();
$_SESSION['location'] = $_GET['location']; // Passed in from a webform.
?>

Code:
<?php
// Use session variable
session_start();
echo $_SESSION['location'];
?>

[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Thanks! I actually just did that, although a little differently but the same concept. In the one script I used $location = $_GET['foo'] and in the other script I put "script.php?foo=.'$location.'";

I appreciate it!
 
that's not the same concept. in your code you are simply appending data to a query string. this would not work if, for example, the page contained a post form and you had not also adjusted the form action or added hidden fields.

sessions are a better way to go. if, for whatever reason, cookies do not work on your setup, php falls back on url rewriting in the manner that you have described (but it does so on the fly and appending only a session identifier).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top