Hi,
i have found a great tutorial on how to use php to simple create a navigation and than links here:
http://www.sebastiansulinski.co.uk/tutoria...nd_page_include
(if its not allowed to post links please remove it)
lets say i will have my web page in 2 languages. and i will have 3 subpages (home, links, contacts)
Ill put a little flags icons in top right corner for selecting a language.
So now lets say i open up the links page and i click on a different language. How do i store the previous
page i was on and show up the same page in a different language?
Hope i made it clear enough for you guys to understand what i am trying to achieve.
Best regards,
HEki
PHP and sending more than 1 parameter
Started by HEki_, Aug 11 2009 01:51 PM
2 replies to this topic
#1
Posted 11 August 2009 - 01:51 PM
#2
Posted 11 August 2009 - 06:01 PM
$_SERVER['HTTP_REFERER'] (ref: http://php.net/manua...les.server.php)
That will basically tell you what page the current request was called from. So you can essentially just redirect back to it. You should use caution though, as i here certain Anti-viruses actually block this variable from being sent to the server.
Another option would be to just tack $_SERVER['REQUEST_URI'] onto the "change language" link's query string, and redirect back to that.
And yet another option, which i would recommend: Just add the language you want to use as part of the query string of the current page, and then process from there. i.e:
That will basically tell you what page the current request was called from. So you can essentially just redirect back to it. You should use caution though, as i here certain Anti-viruses actually block this variable from being sent to the server.
Another option would be to just tack $_SERVER['REQUEST_URI'] onto the "change language" link's query string, and redirect back to that.
And yet another option, which i would recommend: Just add the language you want to use as part of the query string of the current page, and then process from there. i.e:
if($_GET['lang'] == 'en-us'){
// Change the language
}
// Continue loading the site in the new language without having to redirect
#3
Posted 11 September 2009 - 02:25 PM
Here is an example of using a session var for storing the localization (langauge) type. All you then would need to figure out is how you want to interpret the URL and pass that on to the links. If it were me, i would throw the query_string into an array. then call the ?n array in the language change URLs.
The benefit for using a session/cookie is users wont have to keep changing the language on every page visit, (IE Home, Links Contacts etc).. Its stored in a session and for every page visit it will check the session['localization'] and display the correct language..
The benefit for using a session/cookie is users wont have to keep changing the language on every page visit, (IE Home, Links Contacts etc).. Its stored in a session and for every page visit it will check the session['localization'] and display the correct language..
<?php
session_start();
$localization = $_SESSION['localization']; //Language session vars
?>
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div id="right"> <a href="">en-us</a><br/>
<a href="?l=en-gb">en-gb</a><br/>
</div></td>
</tr>
<tr>
<td colspan="2">
<?php
switch ($_GET['l']){
default:
if (isset($localization) && $localization =='en-us') {
echo 'This is the en-us language';
}else {
$localization = 'en-us';
echo '$localization set to en-us';
echo 'This is the en-us language';
};
break;
case 'en-gb':
if (isset($localization) && $localization =='en-gb') {
echo 'This is the en-gb language';
}else {
$localization = 'en-gb';
echo '$localization set to en-gb';
echo 'This is the en-gb language';
}
break;
}
?></td>
</tr>
</table>
Edited by NDBoost, 11 September 2009 - 02:38 PM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
