Jump to content


Photo

setcookie inside of a class not working


  • Please log in to reply
6 replies to this topic

#1 enerjiza

enerjiza
  • Members
  • PipPip
  • Member
  • 11 posts
  • LocationDallas,Texas

Posted 17 July 2006 - 03:56 AM

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?
setcookie("sbn_access", $row['username']."_".$row['password'], time()+2592000);

Yes, I have tried setting the domain and directory.
---------------------------------------------------------------[br] SAVE PHPFREAKS.COM[br]---------------------------------------------------------------

#2 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 17 July 2006 - 04:03 AM

make sure you did not send any header information before setcookie();
Life's too short for arguing.

#3 enerjiza

enerjiza
  • Members
  • PipPip
  • Member
  • 11 posts
  • LocationDallas,Texas

Posted 17 July 2006 - 02:11 PM

would starting and setting sessions count?
---------------------------------------------------------------[br] SAVE PHPFREAKS.COM[br]---------------------------------------------------------------

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 17 July 2006 - 02:16 PM

would starting and setting sessions count?

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.

#5 enerjiza

enerjiza
  • Members
  • PipPip
  • Member
  • 11 posts
  • LocationDallas,Texas

Posted 17 July 2006 - 02:39 PM

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');
		}
	}
Here is my function, maybe that will help out.  I'm running on IIS windows 2000.
---------------------------------------------------------------[br] SAVE PHPFREAKS.COM[br]---------------------------------------------------------------

#6 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 17 July 2006 - 02:49 PM

is this a function or class' member function?
Life's too short for arguing.

#7 enerjiza

enerjiza
  • Members
  • PipPip
  • Member
  • 11 posts
  • LocationDallas,Texas

Posted 17 July 2006 - 08:27 PM

this is a function inside of a class.
---------------------------------------------------------------[br] SAVE PHPFREAKS.COM[br]---------------------------------------------------------------




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users