Posted by Nicole on 10/25/05 10:42
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
Navigation:
[Reply to this message]
|