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>Untitl ed Document</title>
</head>
<body>
<p> <a href="functions .php?FuncToExec =countrySelectU S">Execute countrySelect
function</a></p>
</body>
</html>
I then have a functions.php file:
<?php session_start() ;
session_registe r ("country");
$HTTP_SESSION_V ARS ["country"] = $country;
$country="UK"; //default
?>
<?php
if($FuncToExec == "countrySelectU S"){
countrySelectUS ();
}?>
<html>
<head>
<meta http-equiv="refresh" content="12; URL=thiscountry .php">
<title>Untitl ed 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>Untitl ed 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
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>Untitl ed Document</title>
</head>
<body>
<p> <a href="functions .php?FuncToExec =countrySelectU S">Execute countrySelect
function</a></p>
</body>
</html>
I then have a functions.php file:
<?php session_start() ;
session_registe r ("country");
$HTTP_SESSION_V ARS ["country"] = $country;
$country="UK"; //default
?>
<?php
if($FuncToExec == "countrySelectU S"){
countrySelectUS ();
}?>
<html>
<head>
<meta http-equiv="refresh" content="12; URL=thiscountry .php">
<title>Untitl ed 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>Untitl ed 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
Comment