0

I had a small problem when I try to write this code.

header("Location: question.php?id='$qid'");

It prints this:

question.php?id='$qid

But this not what I want, I want to print the value of $qid,

jeremy
  • 9,965
  • 4
  • 39
  • 59

3 Answers3

0
header("Location: question.php?id=$qid");

should work

Nebojsa Susic
  • 1,220
  • 1
  • 9
  • 12
0

Recommended version:

header("Location: question.php?$qid");

This way trick also work for me if you separate as variable:

$redirect = 'question.php?'.$qid;
header('Location: '.$redirect);

It is also good to set type of redirecting HTTP status as:

header("Location: question.php?$qid", TRUE, 301);

Which means that it will moved permanently as status code 301 and replace a data to changed values. Please see PHP.net manual for header().

Don't forget to add exit(); status if you want to prevent for buffering output if you have some errors or unexpected stopped as sample:

header("Location: question.php?$qid", TRUE, 301);
exit();

Here is HTTP sample code on Wiki how it really works behind PHP header(): http://en.wikipedia.org/wiki/URL_redirection#HTTP_status_codes_3xx

Marin Sagovac
  • 3,932
  • 5
  • 23
  • 53
-2
header("Location: question.php?id='".$qid."'");
LK-CHF
  • 1
  • @Blackberry try `header("Location: question.php?id=$qid");` or `header("Location: question.php?id=".$qid);` – meda Jul 14 '14 at 19:27
  • 2
    Granted this user's answer most likely won't work, but don't just say "didn't work" - report back with more details. What happened when you tried it? In this case, since it's in a URL, it probably threw excess quotes in, right? BTW, @meda has the right idea. – patricksweeney Jul 14 '14 at 19:28
  • I add the single quotes because I don't know if you needed them, but you can simply remove them and end up with @meda suggestion... – LK-CHF Jul 15 '14 at 20:04