Jump to content

setcookie inside of a class not working


enerjiza

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.
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.