izy Posted May 17, 2007 Share Posted May 17, 2007 Hy! Subject: How to make URL Redirections from one PHP Page / site to another webpage in same website or different in PHP? I have PHP multilanguage webpage and I have all content of pages translated into english and german language. Problem: I'm watching content of page in english language(on that link: /index.php?page=out&id=509&lang=en) On second step I want to see the same content of page which I saw before in german language(/index.php?page=out&id=509&lang=de ). Problem is that my code/webpage always links you to first page of langauge(index) which we choose. Please give me an example how to fix it up. Thanks in advance i. Link to comment https://forums.phpfreaks.com/topic/51785-how-to-make-url-redirections-from-one-php-page-to-another-webpage/ Share on other sites More sharing options...
neel_basu Posted May 17, 2007 Share Posted May 17, 2007 Method # 1. header("Location: http://www.example.com/"); Method # 2. <META http-equiv="refresh" content="2; URL=http://example.com/"> Method # 3. Use Javascript Using Method # 3. Is Discouraged. Link to comment https://forums.phpfreaks.com/topic/51785-how-to-make-url-redirections-from-one-php-page-to-another-webpage/#findComment-255174 Share on other sites More sharing options...
Wuhtzu Posted May 17, 2007 Share Posted May 17, 2007 So you mean if you are currently watching index.php?page=out&id=509&lang=de and you on that page change the language to english you get redirected to index.php?lang=en so your site "forgets" which page you were watching when you change language? If that is your problem then the following could be a solution. When you create the link which your language select box redirects to use the following method: <?PHP $request_query = "page=out&id=509&lang=de"; function create_language_link($language){ $request_query = "page=out&id=509&lang=de"; $request_query = preg_replace("/&lang=(en|de)/","",$request_query); $link = "index.php" . "?" . $request_query . "&lang=" . $language; return $link; } ?> This takes the query string which index.php was requested with and removes any language queries. Then it puts it together with "index.php?" and a new language query specified in by $language in the function call. So the following will create a link for your language select box and remember where you were: echo create_language_link("de"); Wuhtzu Link to comment https://forums.phpfreaks.com/topic/51785-how-to-make-url-redirections-from-one-php-page-to-another-webpage/#findComment-255191 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.