Header Function Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
neesley
Forum Commoner
Posts: 26
Joined: Tue Aug 31, 2010 3:22 am

Header Function Question

Post by neesley »

I have a page built of php includes. One of which is a submit form along with a script that posts to itself.

The problem is that since the content is in an include and the parent page already has header info, I can't use the header function to redirect after the form has been processed. One solution of which I can think is to simply remove the script to a separate file. This seems rather inelegant compared to having everything in one document.

Thoughts? Thanks.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Header Function Question

Post by AbraCadaver »

As long as the processing script doesn't output anything then you can use header(). Don't include the form if you don't need it:

Code: Select all

if(!isset($_POST['submit'])) {
   //include form
} else {
  //include form processing script
}
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
neesley
Forum Commoner
Posts: 26
Joined: Tue Aug 31, 2010 3:22 am

Re: Header Function Question

Post by neesley »

Thanks man. What a big help!

I was echoing a line of text as well. Once that was out it worked fine.
Post Reply