You are here: Problem with session variables? « All PHP « IT news, forums, messages
Problem with session variables?

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация