Problem with session variables?
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Problem with session variables?

From: Nicole <nickywebsterjohns@yahoo.co.uk>
Date: Tue Oct 25 2005 - 09:42:38 CEST

Hi

I'm trying to use a function to set a session variable. I have three files:

The first file has:

<?php session_start(); // This connects to the existing session
?>
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<p> <a href="functions.php?FuncToExec=countrySelectUS">Execute countrySelect
function</a></p>
</body>
</html>

I then have a functions.php file:

<?php session_start();
session_register ("country");
$HTTP_SESSION_VARS ["country"] = $country;
$country="UK"; //default
?>
<?php
if($FuncToExec == "countrySelectUS"){
countrySelectUS();
}?>
<html>
<head>
<meta http-equiv="refresh" content="12; URL=thiscountry.php">
<title>Untitled Document</title>
</head>
<body>
<?php
function countrySelectUS() {
$country="US";
echo "new country is: " . $country;
}
?>
</body>
</html>

And finally thiscountry.php:

<?php session_start(); ?>
<html>
<head>
<title>Untitled Document</title>
</head>

<body>
You are in
<?php echo $country ?>

</body>
</html>

However when i click on the link in the first page, the functions.php page
displays saying
'new country is: US'

but the final page gets displayed with:
'You are in UK'

The function is obvioulsy being run, but for some reason the change in value
for country isnt being 'stored' as part of the session, only the value
assigned when its created.

Thats not how I was understanding they should work

Can anyone explain what I have done wrong?

Many thanks for any help given

N
Received on Mon Nov 21 02:49:33 2005