0

I'm trying to redirect with this code:

header("Location: ?pid='".$_GET['pid']."'");
die();

When I write a simple echo $_GET['pid']; the value is good but then when I introduce this variable in the header it return something like 27%27 and thats not true true value

Whats the problem here?

Thank you

2
  • 3
    it's the way you're using the quotes. Remove the single quotes. See the answer below, that's how. Commented Mar 6, 2016 at 15:19
  • complete working example posted use url_encode function Commented Mar 6, 2016 at 15:37

2 Answers 2

2

You have quotes within quotes. Try this instead:

header('location: ?pid='.urlencode($_GET['pid']));

The urlencode() function takes care of any reserved characters in the url.

Description

string urlencode ( string $str )

This function is convenient when encoding a string to be used in a query part of a URL, as a convenient way to pass variables to the next page.

Sign up to request clarification or add additional context in comments.

Comments

0

Try to rewrite without single quotes in location, because %27 is html character code for single quote:

header("Location: ?pid=".$_GET['pid']);
die();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.