enerjiza Posted July 17, 2006 Share Posted July 17, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14811-setcookie-inside-of-a-class-not-working/ Share on other sites More sharing options...
hvle Posted July 17, 2006 Share Posted July 17, 2006 make sure you did not send any header information before setcookie(); Quote Link to comment https://forums.phpfreaks.com/topic/14811-setcookie-inside-of-a-class-not-working/#findComment-59154 Share on other sites More sharing options...
enerjiza Posted July 17, 2006 Author Share Posted July 17, 2006 would starting and setting sessions count? Quote Link to comment https://forums.phpfreaks.com/topic/14811-setcookie-inside-of-a-class-not-working/#findComment-59378 Share on other sites More sharing options...
wildteen88 Posted July 17, 2006 Share Posted July 17, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/14811-setcookie-inside-of-a-class-not-working/#findComment-59387 Share on other sites More sharing options...
enerjiza Posted July 17, 2006 Author Share Posted July 17, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/14811-setcookie-inside-of-a-class-not-working/#findComment-59412 Share on other sites More sharing options...
hvle Posted July 17, 2006 Share Posted July 17, 2006 is this a function or class' member function? Quote Link to comment https://forums.phpfreaks.com/topic/14811-setcookie-inside-of-a-class-not-working/#findComment-59423 Share on other sites More sharing options...
enerjiza Posted July 17, 2006 Author Share Posted July 17, 2006 this is a function inside of a class. Quote Link to comment https://forums.phpfreaks.com/topic/14811-setcookie-inside-of-a-class-not-working/#findComment-59628 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.