Jump to content

Get the address including any $_get variable


Matpatnik

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...