Jump to content

Language Session not being sent to pages


barney0o0

Recommended Posts

Hi Folks

 

At the top of each page i have

 

<?php $_SESSION['lang'] = (isset($_GET['lang'])) ? $_GET['lang'] : "en"; ?>
<?php $suffix = mysql_escape_string($_SESSION['lang']);?>

 

Throughout the site a have 2 buttons (one english and one italian) which has

<a href="?lang=it"

 

..now this refreshes the same page fine, however if i change the language, then go to another page it defaults back to english...

 

Sorry, ive been working on this site off and on, mades changes and taken bit from here an there so i just lost the flow.

 

Many thanks in advance

erm...well, on the 2 main buttons (for selecting the language) i just used;

 

<a href="?lang=it"

 

 

...wouldnt  this be adequate in setting the session variable?

 

Conker87

 

so i need to put the session literally at the top?

 

ive got;

 

<?php require_once('Connections/***.php'); ?>
<?php
session_start();
$_SESSION['lang'] = (isset($_GET['lang'])) ? $_GET['lang'] : "en";
?>
<?php $suffix = mysql_escape_string($_SESSION['lang']);?>

 

...would my original code be ok, but just moving the session position? (sorry i dont want to start cutting and pasting site wide nitl i know im going in the right direction!)

hum..i used another way (that i did originally, then knocked it about a bit), and it works (however i also empty the broser cache (if it makes any difference)

 

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

 

 

oh dear, i spoke way too soon...

 

Ive just tried the pages, and it doesn't default to any language (en), i just an database error. All my databases have a suffix, for example menu_en, menu_it that it derived from session or the language button.

 

So ive just tried a page and it says that database 'menu_' doesn't exist (obviously as it hasnt picked up the session).

 

Could someone make a suggestion...

 

Many thanks in advance

Thanks conker, works like a dream, however now ive come across another problem with the language buttons themselves!

 

 

If, for example im on page

 

http://www.artsouk.biz/about_detail.php?ID=2

 

..then, use the lang button it goes to

 

 

http://www.artsouk.biz/about_detail.php?lang=en

 

...and i loose the id of the page and its contents......(the pages are online, so you can give it a try and see for yourself)

Try:

 

<?php

if ($_SERVER['QUERY_STRING'])
       {
              echo "<a href=\"{$_SERVER['QUERY_STRING']}&lang=it\">Italian</a>";
              echo "<a href=\"{$_SERVER['QUERY_STRING']}&lang=en\">English</a>";
       }
else
       {
              echo "<a href=\"?lang=it\">Italian</a>";
              echo "<a href=\"?lang=en\">English</a>";
       }

?>

 

I haven't tested this, nor do I remember if that's how you can use QUERY_STRING, but give it a shot anyway.

Cheers conker..nearly there!

 

When im on

 

http://www.artsouk.biz/about_detail.php?ID=1

 

and hover over the language buttons, it doesnt include the actual page, however it does detect the ID and language

ie. on hover i get artsouk.biz/ID=1&lang=it

Hey conker..

 

Ive actually got it working with the additional '?'...all seems fine....OR, do you think it'd be better to extend the script like youve just suggested?

 

what im using;

 

<div id="lang">

<?php

if ($_SERVER['QUERY_STRING'])
       {
             
              echo "<a href=\"?{$_SERVER['QUERY_STRING']}&lang=en\">ENGLISH</a>";
       }
else
       {
             
              echo "<a href=\"?lang=en\">ENGLISH</a>";
       }

?>
| <?php

if ($_SERVER['QUERY_STRING'])
       {
             
              echo "<a href=\"?{$_SERVER['QUERY_STRING']}&lang=it\">ITALIANO</a>";
       }
else
       {
             
              echo "<a href=\"?lang=it\">ITALIANO</a>";
       }

?> </div>

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.