TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-14-2007, 03:02 PM   #1 (permalink)
The Wanderer
 
Join Date: Nov 2007
Posts: 23
Thanks: 1
vuthcam is on a distinguished road
Default header VS include

I have been working with php for awhile. The problem i always come across is the argument between header and include commands. When i try to use the include above the header then a sentence of error takes place on the screen. Are there any ways to troubleshoot this problem ? as i have known header command doesn't get along with the include ;).
vuthcam is offline  
Reply With Quote
Old 11-14-2007, 03:10 PM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

What error would that be?
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 11-14-2007, 03:20 PM   #3 (permalink)
The Wanderer
 
Join Date: Nov 2007
Posts: 23
Thanks: 1
vuthcam is on a distinguished road
Default

The error is :

Warning: Cannot modify header information - headers already sent by (output started at C:\htdocs\checkinsValid\includes\function.php:2) in C:\htdocs\checkinsValid\checkin.php on line 70
__________________
Ijajaja
vuthcam is offline  
Reply With Quote
Old 11-14-2007, 03:22 PM   #4 (permalink)
The Frequenter
Prolific Welcomer Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 360
Thanks: 24
Haris is on a distinguished road
Default

Are you using sessions?
Haris is offline  
Reply With Quote
Old 11-14-2007, 03:42 PM   #5 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

This error is caused because of the way the HTTP protocol works. Fundamentally, it works like this:

User (Request Page) -> Server(Processes Request)
Server (Send Header Data) -> User (Interprets Header)
Server (Send Body Data) -> User (Parses Body)
So you can see that if you try sending header information after the body has been processed, then this would naturally result in an error, as you're seeing there. To get around this you should really be aiming for an order of execution like so:

Process PHP -> Process JS -> Process HTML -> Process CSS
Instead of how yours would currently be:

Process PHP -> Process JS -> Process HTML -> Process CSS -> Process PHP -> Process HTML
However, if you don't want to follow that elementary order of execution then you may wish to take a look into the ob_* functions - with a nice start being the ob_start function.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 11-14-2007, 03:52 PM   #6 (permalink)
The Wanderer
 
Join Date: Nov 2007
Posts: 23
Thanks: 1
vuthcam is on a distinguished road
Default

Quote:
Originally Posted by Haris View Post
Are you using sessions?
Yeah Haris!! i am using sessions.

Quote:
Process PHP -> Process JS -> Process HTML -> Process CSS
i dont really catch up this sentence. Please elaborate me more..
__________________
Ijajaja
vuthcam is offline  
Reply With Quote
Old 11-14-2007, 04:08 PM   #7 (permalink)
The Contributor
 
Devels's Avatar
 
Join Date: Nov 2007
Posts: 27
Thanks: 2
Devels is on a distinguished road
Default

Eliminate any undesired white space prior or after <?php ?>.
Your error is saying: output started at c:\htdocs\checkinsValid\includes\function.php:2
So on line 2 your will find undesired white space or an echo that doesn't belong there.
That will fix it.
Devels is offline  
Reply With Quote
Old 11-14-2007, 04:12 PM   #8 (permalink)
The Frequenter
Prolific Welcomer Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 360
Thanks: 24
Haris is on a distinguished road
Default

Quote:
Originally Posted by vuthcam View Post
Yeah Haris!! i am using sessions.



i dont really catch up this sentence. Please elaborate me more..
Make sure session_start(); is at the top of the file.
Haris is offline  
Reply With Quote
Old 11-14-2007, 04:20 PM   #9 (permalink)
The Wanderer
 
Join Date: Nov 2007
Posts: 23
Thanks: 1
vuthcam is on a distinguished road
Default

Quote:
Originally Posted by Devels View Post
Eliminate any undesired white space prior or after <?php ?>.
Your error is saying: output started at c:\htdocs\checkinsValid\includes\function.php:2
So on line 2 your will find undesired white space or an echo that doesn't belong there.
That will fix it.
I think this is not caused by the white space in this situation meanwhile no white space prior of after <?php ?>. The problem is the include and header. I am sure about the error but i cannot fix that problem hehe.. as i have read somewhere before, they said that we cannot this problem usually caused by using the include before the header command..

Ths for you suggestion..Devel :)
__________________
Ijajaja
vuthcam is offline  
Reply With Quote
Old 11-14-2007, 04:22 PM   #10 (permalink)
The Wanderer
 
Join Date: Nov 2007
Posts: 23
Thanks: 1
vuthcam is on a distinguished road
Default

Come on dude, my session_start() always stands on the peak ;)
__________________
Ijajaja
vuthcam is offline  
Reply With Quote
Old 11-14-2007, 05:30 PM   #11 (permalink)
The Wanderer
 
Join Date: Nov 2007
Posts: 23
Thanks: 1
vuthcam is on a distinguished road
Default

The solution :

if this error happens when you use include then header Be sure you use :

ob_start () at the most beginning of your code.

ob_start () :This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer.

and ob_flush() at the bottom of your codes

ob_flush() : The buffer contents are discarded after this function is called.

Hope this info can help others who meet such a problem :)
__________________
Ijajaja
vuthcam is offline  
Reply With Quote
Old 11-14-2007, 05:52 PM   #12 (permalink)
The Acquainted
 
wGEric's Avatar
 
Join Date: Nov 2007
Posts: 166
Thanks: 0
wGEric is on a distinguished road
Default

There error isn't because you are using include(). It is because you are outputting data to the browser before PHP has finished processing all code that has to be handled before anything is sent to the browser.

Before anything gets sent to the browser you have to set the headers. You can't set them after you send data to the browser. That is why using header() does not work.
__________________
Eric
wGEric is offline  
Reply With Quote
Old 11-14-2007, 08:51 PM   #13 (permalink)
The Acquainted
Upcoming Programmer 
 
CMellor's Avatar
 
Join Date: Sep 2007
Location: Leeds, UK
Posts: 141
Thanks: 6
CMellor is on a distinguished road
Default

Do not output any HTML after you use the header function, or you'll get the error. If your page has HTML tags in it, have the header function at the very top of the page, after the '<?php'
__________________
Not quite a n00b...
CMellor is offline  
Reply With Quote
Reply



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

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 06:24 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design