PDA

View Full Version : problem using Header in php script.



TheCut
03-01-2003, 04:31 AM
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;
}

?>

orangehairedboy
03-01-2003, 05:45 AM
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

TheCut
03-01-2003, 11:08 AM
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>

orangehairedboy
03-01-2003, 11:10 AM
Does it even try to execute the PHP file? Any error messages???

Nightfire
03-01-2003, 01:43 PM
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; :confused:

orangehairedboy
03-01-2003, 06:47 PM
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; :confused:


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

TheCut
03-01-2003, 11:10 PM
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

Nightfire
03-01-2003, 11:31 PM
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


<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;
?>

orangehairedboy
03-02-2003, 04:31 PM
Where is this script runing from? Your computer or a webserver somewhere out there?

TheCut
03-02-2003, 11:14 PM
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/");
}
?>

orangehairedboy
03-03-2003, 09:22 AM
Try this script to see if it works:



<?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!

TheCut
03-03-2003, 12:42 PM
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

orangehairedboy
03-03-2003, 03:02 PM
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. ;)

TheCut
03-04-2003, 09:14 PM
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

orangehairedboy
03-05-2003, 10:49 AM
You're welcome...and please let us know if it suceeds!

TheCut
03-06-2003, 01:04 AM
Hi folks,

I finally solve the problem that I have been run into. My belief was absolutely right, I went back and look at all my configuration file for PHP and Apache. I found out that I have placed these two lines in the wrong portion of the {httpd configuration file)

AddType application/x-httpd-php .phtml .php
AddType application/x-httpd-php-source .phps

I made the change according to the book that I read, and all the PHP scripts work fine now. Once again, thanks all of your folks for sharing your experience and ideas.