Wednesday, 15 May 2013

php - Un-setting variable in URL gives error -



php - Un-setting variable in URL gives error -

i've been developing multi-lingual website. i've got slight problem though. every time button clicked language variable needs change. did using anchor tag (i.e <a href="?lang=en">english</a> ).

the problem arises when other variables besides language added url. redirect page without getting rid of other variables , changing lang variable. if url contains "var1=value&var2=value&lang=en", alter lang variable , maintain rest are. lang variable can have 3 values: en, az, ru.

the method tried far:

function uri_add_az(){ $uri = $_server['request_uri']; if(isset($_get['lang'])){ $lang = $_get['lang']; unset($lang); } $new_uri = $uri . '?lang=az'; homecoming $new_uri; } <a href="<?php uri_add_az?>">azeri</a>

the problem:

everytime button clicked lang variable gets added url not altered:

/?lang=az?lang=az?lang=az?lang=az

how can create sure not maintain getting repeated , avoid redirect loops?

simply provide finish url :-

<a href="http://yourwebsite.com/<?php uri_add_az(); ?>">azeri</a>

or, if want without reloading of page, have utilize "jquery.history.js" file. https://github.com/browserstate/history.js

history.pushstate(null, 'title of website', "?lang=<?php uri_add_az(); ?>);

thanks

php

No comments:

Post a Comment