I have home page where i have overlay with list of cities as an hyperlink. I have different databases for each city.
So when user clicks a city on runtime the database should be selected. Again if users change the city the database should be changed.
currently I am using below approach:
index.php
<code>
if(!isset($_REQUEST['city']))
{
$_SESSION['city'];
$_SESSION['usercity'] = "";
}
else
{
$_SESSION['usercity'] = $_REQUEST['city'];
$_SESSION['usercity'];
}
</code>
db.php
<code>
if($_SESSION['usercity'] == 'pune')
{
$dbname = 'pune_xxxx';
}
else if($_SESSION['usercity'] == 'hyderabad')
{
$dbname = 'hyderabad_xxxx';
}
else if($_SESSION['usercity'] == 'aurangabad')
{
$dbname = 'aurangabad_xxxx';
}
else if($_SESSION['usercity'] == 'bangalore')
{
$dbname = 'bangalore_xxxx';
}
else
{
$dbname = 'xxxx';
}
</code>
For first time it works fine but if want to change the city its getting failed because of previous DB in session.
Let me know the solution or alternative to this process
Thanks advance
You would need to again do session_start(); after you detect the change in $_REQUEST['city']
and then set the session variable.