How should I write the $location
variable into the header line? Right now it finds nothing... Blank adress bar...
Her开发者_开发技巧e's what I have so far:
$location='/ad?ad_id='.$id_nr;
Header( "Location: $location" );
BTW, this is on my computer, virtual server, the adress is absolute!
It works without the ?ad_id=.$id_nr
part!
Well, the header()
function is header
not Header
and the URI in location headers must be absolute, not relative.
The Location header must be a fully-formed absolute address, starting with http:// or some other protocol like https. You cannot specify a relative URL.
Try this, with mysite.com replaced with the root URL for your site:
<?php
$location='/ad?ad_id='.$id_nr;
Header( "Location: http://www.mysite.com/$location" );
// or, on your local machine
Header( "Location: http://localhost/$location" );
?>
You might consider eventually writing a more useful function to do the work for you:
<?php
function redirect_to($location, $halt = true) {
$root = $_SERVER['HTTP_HOST'];
header("Location: $root/$location");
if ($halt)
exit;
}
?>
Use $_SERVER['HTTP_HOST'] to get the full url.
Don't forget to put an exit after the header call. The script won't stop automatically, you have to tell it to stop.
In your location variable, i don't see a valid file extention eg html or php. Are you sure there is no extension of your files?
$location='/ad?ad_id='.$id_nr;
Header( "Location: $location" );
精彩评论