Reputation: 269
I am using php to redirect a php file:
header("location:viewprofile.php?id=<?php echo $id; ?>");
The problem is the php is not taken as php and is taken literally, how can I echo the variable in this header?
Upvotes: 0
Views: 57
Reputation: 4526
try this :
header("Location: viewprofile.php?id={$id}");
1) notice the capital "L" in Location, although http headers should be case-insensitive (as by the specifications), some browsers treat them as case-sensitive (IE).
2) you should not use relative paths if possible, because if a trailing slash is left by the browser in the url, you might be redirected to the wrong page (i.e. http://domain.com/folder/ will redirect to http://domain.com/folder/viewprofile.php?id=5)
Upvotes: 1
Reputation: 464
No need to echo it. just use the following code:
header("location:viewprofile.php?id=".$id);
the stored value in the variable $id will be attached to the header string.
Upvotes: 0