web_master Posted June 2, 2007 Share Posted June 2, 2007 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 https://forums.phpfreaks.com/topic/54028-change-languages-with-1-click/ Share on other sites More sharing options...
taith Posted June 2, 2007 Share Posted June 2, 2007 after you set the cookie... header("Location: index.php"); or redirect back to the referrer :-) Link to comment https://forums.phpfreaks.com/topic/54028-change-languages-with-1-click/#findComment-267116 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.