Sessions?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
steves
Forum Newbie
Posts: 22
Joined: Wed Feb 22, 2006 9:04 am

Sessions?

Post by steves »

The following code:

Code: Select all

<html><head>
<title>Log In to Database</title>
</head>
<body bgcolor="#FFFFFF">

<?php

session_start();
yields this error:

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /path/file.php:6) in /path/file.php on line 8

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /path/file.php:6) in /path/file.php on line 8

I discovered that NOTHING can go before the session_start(), so I changed the code to:

Code: Select all

<?php

session_start();
<html><head>
<title>Log In to Database</title>
</head>
<body bgcolor="#FFFFFF">
That resulted in this error:

Parse error: parse error in /path/file.php on line 5

What's wrong, and how do I fix it?

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

like before, you forgot to stop php after calling session_start().
steves
Forum Newbie
Posts: 22
Joined: Wed Feb 22, 2006 9:04 am

Post by steves »

like before?

anyway, thanks. that worked.
User avatar
chrys
Forum Contributor
Posts: 118
Joined: Tue Oct 04, 2005 9:41 am
Location: West Roxbury, MA (Boston)

Post by chrys »

Yep, it always has to go before any sort of output, even a blank line.. sometimes that can get you.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

steves wrote:like before?
I was thinking of another user, my mistake.
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

I had a header error once that took forever to figure out. I kept getting an error that said the problem was on the last line of the file which was '?>'. I figured it was an unclosed string or a missing brace somewhere above it. So I took the file apart commenting stuff out searching for that one line problematic code. Ready for the punch line? The last line was actually '?> '. That extra space after the '>' in an included file caused the header error. :lol: :lol: :lol: :lol:
steves
Forum Newbie
Posts: 22
Joined: Wed Feb 22, 2006 9:04 am

Post by steves »

This one's taking me a few minutes to figure out, too. I developed the php - something like 20 files in a tree structure - on my PowerBook G4, with MySQL 5.0.16-max and PHP 5.1.2. Everything worked BEAUTIFULLY!!

Next, I moved everything over to my server - an iMac G5 running OS X Server, with MySQL 4.1.13a and PHP 4.3.11

Figured that'd be no problem. But nothing works! I'm having to go through and debug page by page.

Does anyone know of a simple thing - I dunno, maybe there's a PHP MySQL function that's allowed in 5.0 that isn't in 4.1, or maybe theres a simple setting in php.ini that I need to change.

And by the way, I'm not comfortable enough with the shell to make changes to .ini files without very explicit instructions.

Anyone know where I can go/what I should do?
Post Reply