Thread: Redirect

    #1
  1. No Profile Picture
    Indie Poser Punk
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Wayne, PA
    Posts
    216
    Rep Power
    14
    Ok....I'm stuck, my book is at home and I didn't find anything on php.net. How to I do a simple redirect? I just want people to come to one page and have it automatically kick them to a different page. Thanks!

    ---Jeff
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    63
    Rep Power
    14
    Try:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <?
    $location = "http://servername.com/whatever.htm";
    header("Location: $location");
    ?>[/code]

    Must be at the top of the page so that no other header info is sent.
  4. #3
  5. No Profile Picture
    Indie Poser Punk
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Wayne, PA
    Posts
    216
    Rep Power
    14
    I copied the code and pasted it. Changed the desired URL, and I still only get an Internal Server Error with: Premature end of script headers: /home/usr223/html/redirect.php

    The code you sent is the only thing I had on the page. Thanks!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    63
    Rep Power
    14
    "Premature end of script headers:" means that no header information was sent. Do you have anything else on the page at all? Comments, contitional statements (if, switch, etc.) or blank space?
  8. #5
  9. No Profile Picture
    Indie Poser Punk
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Wayne, PA
    Posts
    216
    Rep Power
    14
    Nothing but that code snippet on the page. There doesn't seem to be any spaces, either. Could something be configured wrong on my server? Thanks!

  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    63
    Rep Power
    14
    Could be. Are you running Linux or Windows?
  12. #7
  13. No Profile Picture
    Indie Poser Punk
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Wayne, PA
    Posts
    216
    Rep Power
    14
    Linux.
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    0
    Rep Power
    0
    Check if your host is inserting auto-generated header info with each page load... this happened to me.

  16. #9
  17. No Profile Picture
    Indie Poser Punk
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Wayne, PA
    Posts
    216
    Rep Power
    14
    Ok...I just tried this code on a different Linux server:

    <? php
    $location = "http://www.dirtragmag.com";
    header("Location: $location");
    ?>

    And it says there is an error in line 3. Note that this is the only code, at all, that I have on the page. Oh boy. Thanks!

  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    63
    Rep Power
    14
    When I tried the code you posted on my own server, it generated an error too. I removed the " php" after the "<?" and it worked. Shouldn't make a difference, but the space before it might.

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <?
    $location = "http://www.dirtragmag.com";
    header("Location: $location");
    ?>
    [/code]

    [This message has been edited by chris22 (edited October 26, 2000).]
  20. #11
  21. No Profile Picture
    Indie Poser Punk
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Wayne, PA
    Posts
    216
    Rep Power
    14
    Wholly crap! That did it. Thanks!!
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2000
    Location
    Indiana
    Posts
    614
    Rep Power
    15
    Hmm.. that's odd. Having <?php used to be the 'clean' way to code.

    maybe header("Location: $locationnn"); would do it. (in perl you need to have the to new line's to tell the browser/server it's the end of the page headers... but I don't think you need it in PHP.. but worth a try)
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Melbourne, Victoria, Australia
    Posts
    104
    Rep Power
    14
    You definately don't need the two newline characters, php sorts all the header formatting out for you.

    As for the <? php, should work with <?php (no space before php)

    Josh
  26. #14
  27. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    6
    Rep Power
    0
    why not use:

    <SCRIPT Language="JavaScript">
    document.location="http://www.bla.com";
    </SCRIPT>

    ------------------
    Greetings lewi

Similar Threads

  1. post data to new window then do redirect
    By theDano in forum PHP Development
    Replies: 2
    Last Post: January 24th, 2004, 06:08 PM
  2. jsp forward vs redirect +patterns
    By bculp2000 in forum Java Help
    Replies: 1
    Last Post: December 27th, 2003, 11:49 AM
  3. Change form redirect location from dropdown.
    By stanbridge in forum HTML Programming
    Replies: 7
    Last Post: November 19th, 2003, 05:44 PM
  4. Need help: redirect to page based on text in URL
    By JPElectron in forum HTML Programming
    Replies: 2
    Last Post: July 18th, 2003, 11:44 PM
  5. javascript - cookie based redirect... not working?
    By drgroove in forum JavaScript Development
    Replies: 4
    Last Post: July 4th, 2003, 01:55 AM

IMN logo majestic logo threadwatch logo seochat tools logo