Matpatnik Posted May 31, 2007 Share Posted May 31, 2007 Hi guys, I have a quick question: I'm using $_SERVER['php_self'] to get the page where the user is but it only show the name of the fileIs there a way that I can show to them the whole address including any $_GET variable in it.I'm building a website that use 2 languages and I do the switch with the $_GET variable. I want them to be able to click on the button and switch to an other language but stay at the same page.The whole site is on index.php, all the other page are include by the index.Is it possible without using JavaScript and cookies?Thank you for your help Link to comment Share on other sites More sharing options...
Lulzim Posted May 31, 2007 Share Posted May 31, 2007 I'm building a website that use 2 languages and I do the switch with the $_GET variable. I want them to be able to click on the button and switch to an other language but stay at the same page.You can redirect users using http_referer when they change the language, which redirects them to the exact pagesomething like this:<?//code to change the languageheader("Location:".$_SERVER["HTTP_REFERER"]);?> If you still want to get the current address, you can use some combinations of $_SERVER $_SERVER["SERVER_NAME"].$_SERVER["SCRIPT_NAME"]."?".$_SERVER["QUERY_STRING"]; Read here for morehttp://php.net/reserved.variables Link to comment Share on other sites More sharing options...
vijay Posted May 31, 2007 Share Posted May 31, 2007 Hi..yea u can do that for that check the dump of server var like echo "<pre>"; print_r($_SERVER); echo "</pre>"; echo "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; Regards,Vijay Link to comment Share on other sites More sharing options...
Matpatnik Posted May 31, 2007 Author Share Posted May 31, 2007 Thank you for your help I end up withy that: $lang = $_GET['lang'];$string = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];if ($lang == "en") { $self_fr = "<a href=\"http://" . str_replace("lang=en", "lang=fr", $string) . "\">Français</a>"; $self_en = "English";} else { $self_en = "<a href=\"http://" . str_replace("lang=fr", "lang=en", $string) . "\">English</a>"; $self_fr = "Français";} and it work fine Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.