Jump to content

How to make URL Redirections from one PHP Page to another webpage?


Recommended Posts

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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.