🔒 Locked
[web] PHP Problem
Advertisement
Original Post
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?
As a test, try putting the "<?php" as the first line in the file (no blank lines before it, no whitespace).
Put session_start() before any page output.
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
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
My php file starts like this:
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.
#! /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.
Quote:
Original post by Sander
Try removing the empty line between the #!.... and the <?php lines.
I think that fixed it, thanks!
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.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement