1,105,406 Community Members

Setting a cookie variable from $id = $row["id"];

Member Avatar
DaveyMoyes
Junior Poster
122 posts since May 2009
Reputation Points: -1 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi Everyone, Hoping someone here can help me fix this problem I have of setting a cookie variable from a databse $id = $row["id"]; variable.

This seems to work fine when using session data, but I am trying to use cookies and I am a bit stuck. . .

here is the code I have been trying with, you will see where I am setting the cookies, but I need to make the cookie variable = $row ["id"]

if ($_POST['sms'] != "") {

	include_once "../includes/config.php";
	// Be sure to filter this data to deter SQL injection, filter before querying database
	$sms = $_POST['sms'];
	 //strip slashes
	$sms = stripslashes($sms);
	 //stripping tags
	$sms = strip_tags($sms);

	$sql = mysql_query("SELECT id FROM minibays WHERE creff='$sms'");
    $numRows = mysql_num_rows($sql);

	if ($sms = "") {
		$msg_to_user = '<br /><br /><h4><font color="#484848">Please enter your secure sms code</font></h4>';
	} else if ($numRows > 0) {
		/*
		Start sessions											
		*/
			$id = $row["id"];
        	//$_SESSION['SESS_MEMBER_ID'] = $id;		   
		   	setcookie("id", "id", time()+86400);
			setcookie("id"," ' . $id . '", time()+86400);
			setcookie("id"," ' . $id", time()+86400);
			setcookie("id"," " . $id . "", time()+86400);
							
			$securecode = $row["securecode"];
			//$_SESSION['SESS_SECURE_CODE'] = $securecode;
			setcookie("securecode"," ' . $securecode . '", time()+86400);
			
			$creff = $row["creff"];
			//$_SESSION['SESS_CREFF'] = $creff;
			setcookie("creff","$creff", time()+86400);
			//$creff = $row["creff"];
			//$_SESSION['SESS_CREFF'] = $creff;
			
		/*
		Login and go to members area											
		*/	
		//header("location: members.php?$_SESSION[id]");
		//header("Location: members.php?id=".$id."");
		header("Location: members.php?id=$id");
		
		exit ();
	} else {

Any help would be great thanks :)

Member Avatar
cereal
Posting Virtuoso
1,710 posts since Aug 2007
Reputation Points: 461 [?]
Q&As Helped to Solve: 345 [?]
Skill Endorsements: 44 [?]
 
0
 

Check line 23: setcookie("id", "id", time()+86400); the second argument, the value, is "id" while it should be $id: setcookie("id", $id, time()+86400);

Member Avatar
Biiim
Posting Pro
504 posts since Oct 2011
Reputation Points: 85 [?]
Q&As Helped to Solve: 86 [?]
Skill Endorsements: 9 [?]
 
0
 

Heres how i set cookies

setcookie("token", $token, $expire, "/");

The last variable "/" is the path the cookie is available in, which had me confused for awhile when i first got into cookies.

If you set a cookie in a directory called setup, http://example.com/setup/ that cookie is only available in that directory and wont exist on http://example.com/ setting the path to '/' makes the cookie available on the whole domain

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: