HI
I'm a novice at php and am stuck with what I expect should be simple.
The first section works but as soon as I change it, to use a variable for the redirect, it doesn't work.
<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://example.com/cgi-bin/mainpage/" );
?>
<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: $_SERVER["SCRIPT_URI"]" );
?>
What have I done wrongly?
bazz
angst
03-08-2010, 08:56 PM
<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: " . $_SERVER["SCRIPT_URI"] );
?>
Fou-Lu
03-08-2010, 08:57 PM
Is SCRIPT_URI a commonly defined cgi directive? I'm thinking that its not a commonly defined one. Too bad I can't test this one :(
angst
03-08-2010, 09:00 PM
either way, the syntax was wrong. can't use nested double quotes.
Shorter example:
header("Location: ". $_SERVER["SCRIPT_URI"] ,TRUE,301);
See header() reference: http://us3.php.net/manual/en/function.header.php
Fou-Lu
03-08-2010, 09:12 PM
either way, the syntax was wrong. can't use nested double quotes.
Yes indeed, and the complex doesn't really like being evaluated in that context too.
Shorter example:
header("Location: ". $_SERVER["SCRIPT_URI"] ,TRUE,301);
See header() reference: http://us3.php.net/manual/en/function.header.php
Thats interesting; I can't say I've ever done it that way before, but it looks like it would work acording to the api. Nice find on that one!
Guys thanks.
I was stupid to not realise I was redirecting to the redirect script (DUH!!).
I need to redirect to the same domain but to the file /cgi-bin/mainpage.
Should I use a relative uri or an absolute one? It seems to work either way now.
<?
$web_uri = $_SERVER["SCRIPT_URI"];
$file_uri = "cgi-bin/mainpage/";
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: $web_uri$file_uri" );
?>
bazz
Fou-Lu
03-08-2010, 09:14 PM
Guys thanks.
I was stupid to not realise I was redirecting to the redirect script (DUH!!).
I need to redirect to the same domain but to the file /cgi-bin/mainpage.
Should I use a relative uri or an absolute one? It seems to work either way now.
<?
$web_uri = $_SERVER["SCRIPT_URI"];
$file_uri = "cgi-bin/mainpage/";
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: $web_uri$file_uri" );
?>
bazz
I find that relative mostly works, but according to the location specification its supposed to be absolute. So I'd use absolute all the time.
mlseim
03-09-2010, 01:58 AM
Ambrose ... you're wandering a little far from home (Perl) aren't you?
... just kidding.
we'll let you dabble with PHP if you really want to.