Jump to content
xisto Community
Jonnyabc

Php Cookie Error Warning: Cannot modify header information

Recommended Posts

I've done some research on the internet about the following issue, and think I have a small understanding of the issue at hand. I am receiving the following error(s) on my new sub-domain site at SocialCite when I attempt to login with the valid username "Jonnyabc" and password "jonnyabc".

Warning: Cannot modify header information - headers already sent by (output started at /home/jonnyabc/public_html/global.php:2) in /home/jonnyabc/public_html/global.php  on line 130Warning: Cannot modify header information - headers already sent by (output started at /home/jonnyabc/public_html/global.php:2) in /home/jonnyabc/public_html/global.php on line 131

I had a problem with another piece of code, and all of the problems I seem to be having evolve around setting cookies. From what I have read, it is understood to place this code (or reference thereof) at the very, very top of the page before the <html> tag.

Here's the very basic psuedocode for the related functions of the global.php file:

function login(...)	 logout(...)	 check database	 if all is true		  setCookie(...username...)		  setCookie(...password...)function logout(...)	 if cookie username set, setCookie(...username...)	 if cookie password set, setCookie(...password...)

Originally, I was having problems with the logout() cookies, but have finally gotten that resolved. Now I am having problems with setting the cookies in login() when "all is true". The code works fine locally running WampServer, but not on the website. I am willing to believe that setting the cookies twice on the same page creates this error, but I am not certain of that.

Please advise.

Share this post


Link to post
Share on other sites

Served pages have a similar structure to that of e-mails. Headers are always supposed to come first before the page's content is received. The "headers already sent" message is due to the script echoing (or printing) information before sending headers. Recheck the structure of your code and make sure setcookie comes before all echos and prints.

Share this post


Link to post
Share on other sites

just a blank space sent before you try to set a header will throw that error.post your full code.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.