Jump to content

Archived

This topic is now archived and is closed to further replies.

enerjiza

setcookie inside of a class not working

Recommended Posts

I am using the following setookie code inside an authentication function within my users class.  It never sets the cookie, but when I run the script in a seperate file outside of the class it works perfectly, any ideas?
[code]setcookie("sbn_access", $row['username']."_".$row['password'], time()+2592000);[/code]

Yes, I have tried setting the domain and directory.

Share this post


Link to post
Share on other sites
make sure you did not send any header information before setcookie();

Share this post


Link to post
Share on other sites
[quote]would starting and setting sessions count?[/quote]
No. The only time when it will count is when you send any form of output to the browser, such as a space, newline, text, html etc.

Share this post


Link to post
Share on other sites
[code] Function Authenticate( $username, $password, $remember, $refer )
{
global $db;
$sqlUser = mysql_query("SELECT userID,username,password,access,COUNT(userID) AS count FROM ".$db->dbPrefix."_login WHERE username='".$username."' AND password='".md5($password)."' GROUP BY `userID`") or die(mysql_error());
$row = mysql_fetch_assoc( $sqlUser );
if ( $row['count'] > 0 )
{
if ( $remember > 0 )
{
$data = $row['username']."_".$row['password'];
setcookie("sbn_access", $data, time()+300);
session_register('userID');
session_register('access');
$_SESSION['access'] = $row['access'];
$_SESSION['userID'] = $row['userID'];
session_register('username');
session_register('password');
$_SESSION['username'] = $row['username'];
$_SESSION['password'] = $row['password'];
}
else
{
session_register('userID');
session_register('access');
$_SESSION['access'] = $row['access'];
$_SESSION['userID'] = $row['userID'];
}

mysql_query("UPDATE ".$db->dbPrefix."_login SET lastlogin='".mktime()."', ip='".$ip."' WHERE username='".$username."'") or die(mysql_error());
if ( empty($refer) )
{
header('Location: index.php');
}
else
{
header('Location: '.$refer);
}
}
else
{
header('Location: index.php?errorID=1');
}
}[/code]
Here is my function, maybe that will help out.  I'm running on IIS windows 2000.

Share this post


Link to post
Share on other sites
is this a function or class' member function?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.