Newbie can't set a cookie

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
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Newbie can't set a cookie

Post by Joe »

Hello, Recentlt I have been working on a PHP login script for my website. I want to set a cookie for the username of the person who logs in but every time i try it i get a PHP error in my browser. The error goes like:

Warning: Cannot modify header information - headers already sent by (output started at /home/.sites/27/site244/web/scripts/login.php:3) in /home/.sites/27/site244/web/scripts/login.php on line 5

The PHP code at the top of the document simply gos like:

<?php
$username = $_POST["username"];
setcookie ("username", $username, time()+36000);
?>

Then its the html tags and some more php throughout the rest of the script. What am i doing wrong here. Has anyone ever had a similar problem and they have a little time to help me. Thanks!

Regards



Joe :(
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

Reminds me of this post: viewtopic.php?t=1157
Post Reply