Jump to content

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'];
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.