bonny
bonny

Reputation: 3247

How to convert $_GET into a variable?

I have a problem while using $_GET.

I have a URL that looks like http://www.example.com/404.php?uri=xyz. Now I would like to read out that $_GET['uri'] and convert it into a variable that will be used for a header function later on.

The code looks like that:

$get_uri = $_GET['uri'];
...
if ( empty($_POST['pref_lang']) === false ) {
   header("Location: ../$content/404.php?uri=$get_uri");    
}

But for some reason this does not work. When I change the variable $get_uri to something like $get_uri = "123"; it works. When I will echo out $get_uri = $_GET['uri'] it will echo it out correctly.

It would be great if someone could give me a hint on how to fetch this.

Thanks alot.

Upvotes: 0

Views: 532

Answers (2)

user1696874
user1696874

Reputation: 13

Sorry for late Reply , in my point of view this code should work , could you please check this code and let me know the feed back

<?php  
    $domainName=explode("uri=", "http://www.example.com/404.php?uri=xyz");
    echo $get_uri=$domainName[1];
    if ( empty($_POST['pref_lang']) === false ) {
       header("Location: ../$content/404.php?uri=$get_uri");    
    } 
?>

Upvotes: 0

Barmar
Barmar

Reputation: 780994

You need to encode it properly:

header("Location: ../$content/404.php?" . http_build_query(array('uri' => $get_uri)));

Upvotes: 3

Related Questions