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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New Coder
    Join Date
    Jan 2003
    Location
    U.S.A
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    problem using Header in php script.

    Does anyone had experience with this problem before? Trying to call this script from HTML page, but everytime It gave me a blank page. I'm using PHP Version 4.2.2. Thanks

    This is my do_redirect.php script

    <?

    if ($location == "") {
    header("Location: http://localhost/bookB/redirect_form.html");
    exit;
    } else {
    header("Location: $location");
    exit;
    }

    ?>
    Last edited by TheCut; 03-01-2003 at 09:48 AM.

  • #2
    New Coder
    Join Date
    Mar 2003
    Location
    Tampa, FL
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The reason is because of the localhost part of the URL.

    Localhost always points to 127.168.0.1 - which is the computer you're currently using. So, if anyone tries to click on that link, it will look for a webserver on their own computer!

    Now, if this page was written just for you...with a list of links that [only you can access], then you've just gone about it the wrong way. Using http:// means that you need a web server to return the page. What you'd want then is file://c:/bookB/redirect_form.html.

    Lewis

  • #3
    New Coder
    Join Date
    Jan 2003
    Location
    U.S.A
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi there,

    Thanks for your respond, some how I'm still getting the same problem. When I run this page below from my local server, it does not load my do_redirect.php . All I tried to do is redirect some the URL to a new location. By the way, I already turn on the register_globals in the php.ini config file. Anyone has other suggestion, thanks



    This is my redirect_form.html codes

    <HTML>
    <HEAD>
    <TITLE>Redirection Menu</TITLE>
    </HEAD>
    <BODY>

    <FORM method="POST" action="do_redirect.php">

    <P>Send me to:

    <SELECT name="location">
    <OPTION value="http://www.prima-tech.com">Prima-Tech</OPTION>
    <OPTION value="http://www.thickbook.com/">thickbook.com</OPTION>
    <OPTION value="http://www.php.net/">PHP.net</OPTION>
    <OPTION value="http://www.zend.com/">Zend Technologies</OPTION>
    <OPTION value="http://hotwired.lycos.com/webmonkey/">Webmonkey</OPTION>
    <OPTION value="http://www.zdnet.com/developer/">ZDNet Developer</OPTION>
    </SELECT>

    <INPUT type="submit" name="submit" value="Go!">

    </FORM>

    </BODY>
    </HTML>

  • #4
    New Coder
    Join Date
    Mar 2003
    Location
    Tampa, FL
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Does it even try to execute the PHP file? Any error messages???

  • #5
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Localhost always points to 127.168.0.1
    I think that's 127.0.0.1 (maybe different if you're on a network though?)

    Hard to do this by guessing, but try taking out the exits;

  • #6
    New Coder
    Join Date
    Mar 2003
    Location
    Tampa, FL
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by Nightfire
    I think that's 127.0.0.1 (maybe different if you're on a network though?)

    Hard to do this by guessing, but try taking out the exits;

    Duh...you're right...everyone knows what I meant

  • #7
    New Coder
    Join Date
    Jan 2003
    Location
    U.S.A
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You are right folk, I have written the php script to check out the IP address. It turns out to 127.0.0.1, also my computer runs on P2P network through a router. This IP address is the loop back IP address, so I believe this is the reason that the server does not load my do_redirect.php file. I have tried to run this file by itself, it loaded back to my redirect_form.html file, and no error message display. I also tried to to take out the exit; line, it's still run into the same problem. Any folks has other ideas, please share your, thank a lot.

    TheCut

  • #8
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Just a stab in the dark, but try renaming $location to something else, like $location1, it might be a reserved word for a function or something, if that doesn't do anything, try this
    PHP Code:
    <form method="<?=$PHP_SELF;?>" action="post">
    <SELECT name="location12"> 
    <OPTION value="http://www.prima-tech.com">Prima-Tech</OPTION> 
    </SELECT>
    <input name="submit" type="submit" value="Submit">
    </form>
    <?
    echo $location12;
    ?>

  • #9
    New Coder
    Join Date
    Mar 2003
    Location
    Tampa, FL
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Where is this script runing from? Your computer or a webserver somewhere out there?

  • #10
    New Coder
    Join Date
    Jan 2003
    Location
    U.S.A
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nightfire,

    I have tried that script, it gave me HTTP 404 error (file cannot be found)

    orangehairedboy,

    All my php script is running on my own computer (my own web server). I have no ideas why It keep giving the same problem on my Windows 2000. I have similar web server runs on Windows XP without any problems, all php scripts run very good.

    *By the way, I have no problem running this script from my webserver. It works fine.


    <?php
    //if its MSIE then
    //go to Spoono.com
    if ($name = strstr ($HTTP_USER_AGENT, "MSIE")) {
    Header ("Location: http://www.spoono.com/");
    }
    //else go to to yahoo.com
    else {
    Header ("Location: http://www.yahoo.com/");
    }
    ?>

  • #11
    New Coder
    Join Date
    Mar 2003
    Location
    Tampa, FL
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this script to see if it works:

    PHP Code:
    <?php
    if ($_GET{'location'} == "") { 
    header("Location: http://www.google.com");
    } else { 
    header("Location: $_GET{'location'}");

    ?>
    I noticed that you had <?php on the script that worked and <? on the script that didn't...you never know...I also changed $location to $_GET{location}...make sure you submit the form with the GET method.

    Also, I'm wondering if the script is working fine, but the file it used to point to (the http://localhost/bookB... address) was the problem...

    Let us know how it works!

  • #12
    New Coder
    Join Date
    Jan 2003
    Location
    U.S.A
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The script you have above works fine. I tried to substitute the header with one of my URL, which is http://localhost/bookB/redirect_form.html"); It starts giving me problem. I reviewed the error log page of the Apache server, it shows the following

    [Mon Mar 03 01:09:18 2003] [error] [client 127.0.0.1] Premature end of script headers: c:/php/php.exe

  • #13
    New Coder
    Join Date
    Mar 2003
    Location
    Tampa, FL
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can you open that html file normally in a web browser?

    Also, please provide the PHP error log...

    Edit: different question due to me being stupid and not reading the post.
    Last edited by orangehairedboy; 03-03-2003 at 02:10 PM.

  • #14
    New Coder
    Join Date
    Jan 2003
    Location
    U.S.A
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I can open that redirect_form.HTML in the browser without any problem. It just can not load the do_redirect.php script.

    Okay, here is what I found out. I took the redirect_form.hmtl and do_redirect.php script put them in the Web Server on my Windows XP computer. The code worked very well, without any problem. So I believe I must have done something wrong some where during the process of installing of PHP or Apache. That's why it keeps give problem. I guess that I have to reinstall these software again.

    Lastly, I'd like to say thanks for all your helps. I'm really appreciate them. Thanks

  • #15
    New Coder
    Join Date
    Mar 2003
    Location
    Tampa, FL
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You're welcome...and please let us know if it suceeds!


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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