Forum Moderators: coopster

Message Too Old, No Replies

How to change theme/language in URL

ex. mydomain.com/post.php?id=title&lng=EN&theme=DEF

         

paperso

5:16 pm on Sep 14, 2010 (gmt 0)

10+ Year Member



I was wondering how to change the current language and theme without using cookies and sessions but instead use URL to parse them.

Let say I have this url in english:
mydomain.com/post.php?id=title


So changing the language into russian would be:
mydomain.com/post.php?id=title&lng=EN



Or changing the theme, you parse the url as:
mydomain.com/post.php?id=title&theme=DEF


Thanks \(^_^)/

enigma1

11:29 am on Sep 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You keep track of the requests checking the lng and theme parameters.

This means each time a page is loaded all links displayed need to include the original links + the parameters/values originally requested.

$extra_array = array();
$lng = $_GET['lng'];
$theme = $_GET['theme'];

switch($lng) {
case 'RU':
$extra_array[] = 'lng=RU';
break;
default:
break;
}

switch($theme) {
case 'TH1':
$extra_array[] = 'theme=TH1';
break;
case 'TH2':
$extra_array[] = 'theme=TH2';
break;
default:
break;
}

// So when you build the links you append the extra params variable.
$extra_string = implode('&', $extra_array);
echo '<a href="http://www.example.com/index.php' . (!empty($extra_string)?('?' . $extra_String):'') . '">Home Page</a>';

Or you can create a tiny function to format each link.

The drawback as you see is with the manipulation of the urls which makes content management hard than when using a session or another mechanism. Also if this is for spiders, you can still track their steps exposing different languages/themes without a cookie. (use IP, time on site with the switch parameters and you could initialize a special spider session IP based)

paperso

4:27 am on Sep 20, 2010 (gmt 0)

10+ Year Member



@enigma1 thanks for this script!

I had all links placed under php function so implementing this won't be that hard. Sadly, I don't have idea on how to manage spiders.

enigma1

8:24 am on Sep 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



for spiders you could check the value of the
$_SERVER['HTTP_USER_AGENT']
If it's a known spider it will include a documented string you could check against. There are many ways like using a table of spider strings to check the user agent for. Then you could store the ip/spider string to a specific session without setting a cookie.

paperso

9:29 am on Sep 20, 2010 (gmt 0)

10+ Year Member



Thanks for the reply \(^_^)/