RSS Forums RSS
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2116 | Replies: 5
Reply
Join Date: Dec 2007
Posts: 9
Reputation: gym_shorts is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
gym_shorts gym_shorts is offline Offline
Newbie Poster

php header() redirect issues

  #1  
Dec 20th, 2007
I am having a problem with URL redirection using a mail submission form.

The form is working and sends the mail successfully, the problem lies when I try to redirect the user to a thankyou.php page using header('Location: http://whatever.com/thankyou.php');

When the form is filled in and submitted, the mailform.php page executes but the redirection does not occur, I just get the blank page mailform.php.

Searching the web over my syntax for the header() script looks correct, is there anyway to debug this to see what exactly is occurring? Do I need to do anything on the server side in order to allow this function to work properly?

thanks in advance,

Gym
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2007
Location: St. Vincent and the Grenadines, Caribbean
Posts: 1,038
Reputation: scru is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 47
Featured Poster
scru's Avatar
scru scru is offline Offline
Veteran Poster

Re: php header() redirect issues

  #2  
Dec 20th, 2007
you can put an echo right before it to check if, first of all, that line of code is ever reached. (Of course this echo will cause the header() to throw an error if they are indeed reached, but it's just testing).
Last edited by scru : Dec 20th, 2007 at 5:53 pm.
Reply With Quote  
Join Date: Jul 2007
Posts: 111
Reputation: Designer_101 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
Designer_101 Designer_101 is offline Offline
Junior Poster

Re: php header() redirect issues

  #3  
Dec 21st, 2007
This is a really common problem that occurs when using php to redirect users. The header must be at the top of the page (first thing the browser reads). So i would suggest using the following code instead.

echo("<script>location.href = 'http://whatever.com/thankyou.php';</script>");
This just echos out a javascript redirect. It is a lot easier and more reliable than PHP.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 9
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: php header() redirect issues

  #4  
Dec 21st, 2007
Originally Posted by Designer_101 View Post
This is a really common problem that occurs when using php to redirect users. The header must be at the top of the page (first thing the browser reads).

Wrong. The header can be anywhere in the script. The only thing is, you shouldn't output anything before the header function(not even a html tag). header("location: http://whatever.com/thankyou.php"); is just as good as
echo("<script>location.href = 'http://whatever.com/thankyou.php';</script>");

P.S. header is comparatively faster since its a php function, where as in the other case, it should first 'echo' the redirect script.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Nov 2007
Posts: 435
Reputation: buddylee17 will become famous soon enough buddylee17 will become famous soon enough 
Rep Power: 3
Solved Threads: 85
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro in Training

Re: php header() redirect issues

  #5  
Dec 21st, 2007
Yeah I agree with Naveen. Do your redirect before any echo or print function, <doctype>, or <html> tag. This will also help keep the logic and design separate.
Reply With Quote  
Join Date: Mar 2008
Location: mexabet.biz
Posts: 132
Reputation: mexabet is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 9
mexabet's Avatar
mexabet mexabet is offline Offline
Junior Poster

Re: php header() redirect issues

  #6  
Jul 30th, 2008
I have tried some PHP redirection methods and they all were giving me this error message: Warning: Cannot modify header information - headers already sent by.... on line...
Then I tried this and it works fine. You can even customize it to the number of seconds it takes before redirection occurs.
<?php
   ob_start();
   echo '<meta http-equiv="refresh" content="1;http://www.yourdomain.com/" />';
   ob_flush();
?>
The number "1" before the URL denotes the delay time before redirection.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 1:56 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC