Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-01-2003, 03:31 AM   PM User | #1
TheCut
New Coder

 
Join Date: Jan 2003
Location: U.S.A
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
TheCut is an unknown quantity at this point
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..
TheCut is offline   Reply With Quote
Old 03-01-2003, 04:45 AM   PM User | #2
orangehairedboy
New Coder

 
Join Date: Mar 2003
Location: Tampa, FL
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
orangehairedboy is an unknown quantity at this point
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
orangehairedboy is offline   Reply With Quote
Old 03-01-2003, 10:08 AM   PM User | #3
TheCut
New Coder

 
Join Date: Jan 2003
Location: U.S.A
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
TheCut is an unknown quantity at this point
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>
TheCut is offline   Reply With Quote
Old 03-01-2003, 10:10 AM   PM User | #4
orangehairedboy
New Coder

 
Join Date: Mar 2003
Location: Tampa, FL
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
orangehairedboy is an unknown quantity at this point
Does it even try to execute the PHP file? Any error messages???
orangehairedboy is offline   Reply With Quote
Old 03-01-2003, 12:43 PM   PM User | #5
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
Quote:
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;
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Old 03-01-2003, 05:47 PM   PM User | #6
orangehairedboy
New Coder

 
Join Date: Mar 2003
Location: Tampa, FL
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
orangehairedboy is an unknown quantity at this point
Quote:
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
orangehairedboy is offline   Reply With Quote
Old 03-01-2003, 10:10 PM   PM User | #7
TheCut
New Coder

 
Join Date: Jan 2003
Location: U.S.A
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
TheCut is an unknown quantity at this point
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
TheCut is offline   Reply With Quote
Old 03-01-2003, 10:31 PM   PM User | #8
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
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;
?>
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Old 03-02-2003, 03:31 PM   PM User | #9
orangehairedboy
New Coder

 
Join Date: Mar 2003
Location: Tampa, FL
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
orangehairedboy is an unknown quantity at this point
Where is this script runing from? Your computer or a webserver somewhere out there?
orangehairedboy is offline   Reply With Quote
Old 03-02-2003, 10:14 PM   PM User | #10
TheCut
New Coder

 
Join Date: Jan 2003
Location: U.S.A
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
TheCut is an unknown quantity at this point
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/");
}
?>
TheCut is offline   Reply With Quote
Old 03-03-2003, 08:22 AM   PM User | #11
orangehairedboy
New Coder

 
Join Date: Mar 2003
Location: Tampa, FL
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
orangehairedboy is an unknown quantity at this point
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!
orangehairedboy is offline   Reply With Quote
Old 03-03-2003, 11:42 AM   PM User | #12
TheCut
New Coder

 
Join Date: Jan 2003
Location: U.S.A
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
TheCut is an unknown quantity at this point
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
TheCut is offline   Reply With Quote
Old 03-03-2003, 02:02 PM   PM User | #13
orangehairedboy
New Coder

 
Join Date: Mar 2003
Location: Tampa, FL
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
orangehairedboy is an unknown quantity at this point
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..
orangehairedboy is offline   Reply With Quote
Old 03-04-2003, 08:14 PM   PM User | #14
TheCut
New Coder

 
Join Date: Jan 2003
Location: U.S.A
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
TheCut is an unknown quantity at this point
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
TheCut is offline   Reply With Quote
Old 03-05-2003, 09:49 AM   PM User | #15
orangehairedboy
New Coder

 
Join Date: Mar 2003
Location: Tampa, FL
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
orangehairedboy is an unknown quantity at this point
You're welcome...and please let us know if it suceeds!
orangehairedboy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:05 AM.


Advertisement
Log in to turn off these ads.