Jump to content

Change languages with 1 click?


web_master

Recommended Posts

Hi,

 

ive got an index file. In header is the srcipt for a send cookie to change languages. I have a 3 flags with a link to change language-cookie.

 

Everything is woking fine except that I (user) must click 2 times on a flag to chage a language on site - because the first (reload) time cookie goes to browser and on second click read index file from browser.

 

How can I do to language chage on one click?

 

Thanx!

 

this is a "cookie" below:

 

<?php

//For a reload = 1

if($_GET['lg'] == "") {$lg = 'hu';}

 

 

$languages = array('hu', 'sr', 'en');

 

 

if (isset($_GET['lg']) && in_array($_GET['lg'], $languages)) {

  $lg = $_GET['lg'];

  $_SESSION['lg'] = $lg;

  setcookie('lg', $lg, time()+60*60*24*365);

 

 

} elseif (isset($_COOKIE['lg']) && in_array($_COOKIE['lg'], $languages)) {

  $lg = $_COOKIE['lg'];

  $_SESSION['lg'] = $lg;

 

 

} elseif (isset($_SESSION['lg']) && in_array($_SESSION['lg'], $languages)) {

  $lg = $_SESSION['lang'];

 

} else {

  $lg = $languages[0];

  $_SESSION['lg'] = $lg;

  setcookie('lg', $lg, time()+60*60*24*365);

}

?>

 

the links are:

 

<?php print "<a href=\"index.php?lg=hu\" target=\"_self\"><img src=\"images/language_flags/flag_hu.png\" border=\"0\" alt=\"\"></a>";?>

<?php print "<a href=\"index.php?lg=sr\" target=\"_self\"><img src=\"images/language_flags/flag_sr.png\" border=\"0\" alt=\"\"></a>";?>

<?php print "<a href=\"index.php?lg=en\" target=\"_self\"><img src=\"images/language_flags/flag_en.png\" border=\"0\" alt=\"\"></a>";?>

 

 

Link to comment
Share on other sites

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.