Error trying to use sessions

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

greg
New php-forum User
New php-forum User
Posts: 11
Joined: Wed Nov 13, 2002 6:56 am

Error trying to use sessions

Postby greg » Fri Jan 10, 2003 6:34 am

I copied code (an entire .php file) directly from an online tutorial and received the following error message:

"Warning: Cannot send session cookie - headers already sent by (output started ... on line 14"

Line 14 is simply "session_start();"

The php faq says "... headers can only be sent before all other content, check if your script is sending headers after having already sent content." And, I fix this how?

I have gotten the same or similar messages everytime I have tried to use sessions, even when using code straight from the PHP site.

greg
New php-forum User
New php-forum User
Posts: 11
Joined: Wed Nov 13, 2002 6:56 am

Figured it out

Postby greg » Fri Jan 10, 2003 9:46 am

Session_start() has to be placed above any HTML tags.

KOAK
New php-forum User
New php-forum User
Posts: 4
Joined: Fri Jan 10, 2003 6:14 pm
Location: koak land
Contact:

Postby KOAK » Fri Jan 10, 2003 6:46 pm

it would be pest to do it like:
<?php
session_start();


then go from their.. It's also better to write <?php then just <? anyways.. you prolly have it already figured out if this post is old:)


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 6 guests