
|
View Full Version : Session Error
Falco1199 10-25-2002, 07:18 PM I have this code in an include file: (w/ different variable names)
<?php
session_start();
if (IsSet($var1) && !IsSet(varX)) {
session_register('var1');
session_register('var2');
session_register('var3');
}
?>
var2 and var3 are automatically set if var1 is. But.. I get this error:
Parse error: parse error, expecting `T_VARIABLE' or `'$''
in /path/include.inc on line 4
What's wrong?
Falco1199 10-25-2002, 07:21 PM HA nevermind, saw the problem after reading my post. Even without replies, this forum has helped me...
Falco1199 10-25-2002, 07:30 PM Ugh sorry, new problem after fixing the first:
Warning: Cannot send session cookie - headers already sent by (output started at /path/index.php:12) in /path/include.inc on line 3
Warning: Cannot send session cache limiter - headers already sent (output started at /path/index.php:12) in /path/include.inc on line 3
What's this about?
Talking to yourself is the first sign of madness ;)
Make sure there are no white space at the start of ur code - also make sure the cookie is set first
Falco1199 10-25-2002, 07:54 PM The code starts with <?php.. but there's a return before the session_start call.. Is that OK?
And.. What I'm trying to do is make the cookies not necesarily set, but get them if they ARE set. So.. in this case, they DEFINITELY aren't set. Is there something wrong with this?
Falco1199 10-26-2002, 03:51 PM Sorry, bumping.. Why does this seem like something that happens to everyone at some point?
:(
cortices 10-26-2002, 05:28 PM I can't really tell what's happening from the code you provided. All I can do is tell you what the error means, which you may or may not already know.
Basically, when processing a request, the web server sends first the headers and then the content of the body. Obviously, the name "headers" implies that they are sent *before* the content. Now, headers can be a number of things. Cookies, HTTP redirects, no-cache settings, whatever. The content is the output for your page.
So, just make sure that if you are trying to explicitly set any headers (which you are doing with the session_start(), ie. setting a cookie), that you have *not* output anything to the browser yet.
Be sure to check any included files.
Falco1199 10-26-2002, 11:37 PM I did know this.. but thanks, you did make it a bit more clear than it had been to me. The thing is, the call to session start is in an include file, and that's not at the very top of the page (I realize this NOW...). I have:
<html>
<head>
<meta stuff="stuff">
<?php include("/path/include.inc"); ?>
(rest of code)
For some reason, I was thinking the include file was at the top of the pages.. That was sort of dumb.
So, to get it on top, I would have to edit EVERY page on my site. Fortunately, it's not that much at the moment, and wouldn't kill me, but.. Is there any alternative?
I bet I can guess the answer.. but, it's worth a shot. :bawling:
cortices 10-27-2002, 02:53 AM Heh, well...you could write a quick script to do it, but depending on the number of pages you would probably be able to just edit them manually more quickly. :)
For future reference, this is why *everyone* uses headers and footers. Put all that code (the commong HTML at the top of the page and any common PHP code) into a seperate file, then include it at the top of every page. That way if something needs to be changed, you just have to edit it once and once only.
|