Skip to main content
gamedev.net
🔒 Locked

[web] PHP Problem

Started by guywithknife 7 replies 1.2k views
Original Post
guywithknife
guywithknife
Im trying to write a simple login system and I was going to use sessions, but I couldn't get that to work, so I tried cookies instead, but had the exact same problem with that. So heres the problem: When I try to initialise my cookies/sessions (using session_start() or whatever) I get an error message saying that the headers were already sent. The thing is, there is nothing in my file before this! The error message tells me that the "output started on line x" but the only thing on that line is my "<?php". I dont output anything, in fact I dont DO anything before I try to set up cookies or sessions, but it says I do. Has anyone got any ideas? Anything that may help would be greatly appreciated as I spent all day working on this and still have got no further.. NOTE: the only thing I can think of is that my php scripts run as a CGI, a side effect of the university network administers not trusting something or other because of security issues. Could this be my problem?
markr
markr
If you're using a recent(ish) PHP4, some output buffering should be enabled by default.

If this is the case, you can write (a little) output before the headers.

In any case, it is good practice to do *everything* logic-wise, before you output *any* results.

If your code has a mixture of logic and presentation, it will be unmaintainable. But this is not unusual.

Mark
guywithknife
guywithknife
My php file starts like this:

#! /usr/local/bin/php<?phpsession_start();


No matter how I arrange this code, the error says that output was started on the line my "<?php" is on, no matter what line I put it on.
The "#! /usr/local/bin/php" needs to be there cause of how php was set up on the system. Could that be whats causing it? If so Im gonna have to get in contact with the admins, but if its something I can fix, please let me know.

Thanks for the replies.
wrathgame
wrathgame
remove the
#! /usr/local/bin/php

that should not be required.

~ Tim
guywithknife
guywithknife
Quote:
Original post by Sander
Try removing the empty line between the #!.... and the <?php lines.


I think that fixed it, thanks!
ClarionMedia
ClarionMedia
Quote:
Original post by wrathgame
remove the
#! /usr/local/bin/php

that should not be required.


for arguements sake, that is required when you are running php in cgi mode.
Matt Kimballmatt@clarionmedia.comClarion Media Grouphttp://www.clarionmedia.com

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.