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
,
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
,
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
header("Location: question.php?id='".$qid."'");