Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts

    Redirect to $_SERVER["SCRIPT_URI"] not working

    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.

    Code:
    <?
    Header( "HTTP/1.1 301 Moved Permanently" );
    Header( "Location: http://example.com/cgi-bin/mainpage/" );
    ?>
    Code:
    <?
    Header( "HTTP/1.1 301 Moved Permanently" );
    Header( "Location: $_SERVER["SCRIPT_URI"]" );
    ?>
    What have I done wrongly?


    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    PHP Code:
    <?
    Header
    "HTTP/1.1 301 Moved Permanently" );
    Header"Location: " $_SERVER["SCRIPT_URI"] );
    ?>

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #4
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    either way, the syntax was wrong. can't use nested double quotes.

  • #5
    eak
    eak is offline
    Regular Coder eak's Avatar
    Join Date
    Jun 2002
    Location
    Nashville, TN
    Posts
    354
    Thanks
    0
    Thanked 26 Times in 26 Posts
    Shorter example:
    PHP Code:
    header("Location: "$_SERVER["SCRIPT_URI"] ,TRUE,301); 
    See header() reference: http://us3.php.net/manual/en/function.header.php
    eak | "Doing a good deed is like wetting your pants; every one can see the results, but only you can feel the warmth."

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by angst View Post
    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.

    Quote Originally Posted by eak View Post
    Shorter example:
    PHP Code:
    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!
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #7
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    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.

    Code:
    <?
    $web_uri = $_SERVER["SCRIPT_URI"];
    $file_uri = "cgi-bin/mainpage/";
    Header( "HTTP/1.1 301 Moved Permanently" );
    Header( "Location: $web_uri$file_uri" );
    ?>
    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by bazz View Post
    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.

    Code:
    <?
    $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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #9
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •