Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

88 users online



Having problem with setcookie()

Having problem with setcookie()

Currently viewing this thread: 1 (0 members and 1 guests)


droomagon

droomagon

Neverside Newbie
Status: Offline!

Having problem with setcookie()

I tried the other day to write a login script of my own, so far I can use the session to login and out the user fine, but when I tried to use the cookie to save the info, I get the following error:

Warning: Cannot modify header information - headers already sent by

and it points to line 36, which happens to be the:

setcookie("CartCookie1", xxxname, time() + (86400 * 30));

here are my codes:

$userinput = $_POST["username"];
$pwinput = md5($_POST["password"]);
$matchquery = "SELECT * FROM members WHERE userAcntName = '$userinput' AND userPassword = '$pwinput'";
$result = mysql_query($matchquery);

if (mysql_fetch_row($result)) {
echo "Hi, welcome to my page.\n";
$_SESSION["usernamelogin"] = $userinput;
setcookie("CartCookie1", xyz, time() + (86400 * 30));
echo "Hello $username <BR><a href=\"?do=store\">Go back to store front</a>";
} else {
echo "you are not welcome";
}

---- I tried to erase any spaces in between hoping that'd solve the problem, but that didn't fly... so I'd love any feedback guys, I need help here...

ringpull

ringpull

Neversidian
Status: Offline!

You need to use output buffering.
Before all your php code, have this (and on every page):

PHP:

<?php
ob_start
();
?>


and at the end of all php:

PHP:

<?php
ob_end_flush
();
?>

droomagon

droomagon

Neverside Newbie
Status: Offline!

I solved the problem last night somehow, it was just plainly annoying to have any HTML codes before the setcookie() function. So I took out any HTML there was before it.

Thanks Ringpull, that helps too!~

Geek

Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0163 seconds.