Jump to content

session error in globals


Recommended Posts

There are multiple reasons as to why you're getting this error.

Is there any whitespace before the opening <?php tag on globals.php?

Is there any whitespace before the opening <?php tag on the file in which you're including the globals.php?

Have you tried to include the globals.php multiple times (for whatever reason)?

Provide a little more info please

  • Like 1
Link to comment
Share on other sites

If you want the really technical reason why it's because the server sent data with header data in it to the client via HTTP and then tried to send some more header data.

First up. When you see an error from PHP regarding headers, it's not a bunch of HTML code that you reuse in all your views that show the banner. This is a common mistake for inexperienced developers.

Headers are much more informative and powerful from a developers perspective but completely invisible to the average user usually. They can and will contain useful information.

One of the most important pieces of data headers contain is the status code of the response that was sent back from the server. If everything went swimmingly on the backend side of the application then usually a 200 (OK) status code is sent in the headers. But others can be sent and I'm sure you've seen them. 404 (Not Found), 403 (Forbidden), 500 (Server Error) etc

There are also other pieces of information sent back, things like the content type, location etc.

Moving on. When the client side code, in your case, the POST requests made from the HTML side of your game, or the GET requests made by a user navigation to a different file in your game, sends a request to the server, the server finds the file that should handle the request. Once anywhere in your file tries to send a response back to the client, be it white space outside the php tags, be it and echo "" or a var_dump() or be it a php error, php will generate headers and send it back with the response to the client.

Generally speaking once the client (normally the browser) receives the headers, that's it they are persistent and cannot be changed. This boils down normally to the fact that the browser has received a status 200 from the server so it believes everything went well. If anywhere else in your code tried to send headers after they have been sent, php is gonna throw an error because it knows it can't send more than one set of headers for one request made. For each request there is only one response.

In php if you try to initialise sessions after your headers are sent then there'll be an error thrown like the one you have received. Therefore to fix you try find where headers could have been already sent.

[uSER=53425]Magictallguy[/uSER] said there were a couple of reasons for why you are getting the error. I disagree. There is one reason why you are getting the error. Php/Apache sent headers to the client and it then tried to send more headers. That's the error. That's the reason for the error.

What MTG should have said was, there are couple of common mistakes that caused the error that you should look for when trying to fix the problem.


Now, you'll be asking me, if you even read this, why I went into so much detail.

Simple. If you understand the error, understand what causes the error, then you know what to look for. You can fix it yourself. You don't need to paste code on a forum asking other developers to find your mistake. You'll be able to find it yourself.

Once you can diagnose and fix problems yourself, you'll become a much better developer.

Having a full understanding of the full stack and how HTTP works helps a lot when writing web applications. You should start doing the research.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...