Jump to content

losing session variables


matthew_ellis24

Recommended Posts

I am trying to set up a php based multilanguage site. I thought about using the database for the multilingual content, but it seems more hassle than it's worth for the amount of actual writing on the site.

 

The site is www.carabusonline.co.uk. If you select a language then all fine, but as soon as you navigate away it loses the variable and resorts to english.

 

As always, any help greatly appreciated! Code below:

 

the l: in the top right is my attempt at debugging and is set to:

echo $lang;

 

as defined by session.php, which is included right at the top of the page (on every page before any HTML, with no white space included):

<?php
SESSION_START();
if (isset($_GET['lang'])) {
$lang=$_GET['lang'];
$_SESSION['lang'] = $lang;
}
if(!isset($lang)){
$lang="en";
}
?>

 

The language links are just:

<a href="?lang=es"><img src="flags/es.jpg"></a>

 

To call a page I use

		<?php
      $menu = "menu_".$lang.".html";
  include($menu);
	?>

Link to comment
https://forums.phpfreaks.com/topic/75524-losing-session-variables/
Share on other sites

Try:

 

<?php
SESSION_START();
if (isset($_GET['lang'])) {
$lang=$_GET['lang'];
$_SESSION['lang'] = $lang;
}
if(!isset($_SESSION['lang'])){
$lang="en";
}else{
$lang = $_SESSION['lang'];
}
?>

 

Edit: I assume that was what was meant by the last poster.

well the old code also would of worked fine with some modifications

 

<?php
SESSION_START();
$lang="en";
if (isset($_GET['lang'])) {
$lang=$_GET['lang'];
$_SESSION['lang'] = $lang;
}
else if (isset($_SESSION['lang']))
{
$lang = $_SESSION['lang'];
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.