Cookies not being created?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Cookies not being created?

Post by Jim »

Here's the script that is supposed to create cookies using the input 'user_name' and 'password'.

Code: Select all

<?
include("config.php");

//Validate username/pass against Database
$sql = "SELECT * from IamJim_users where user_name = '$user_name' and password = '$password'";
$query = mysql_query($sql);

$num = mysql_num_rows($query);
echo $num;

	if($num != 1) {
		echo "No such user in our database!  Please <a href="/iamjim/php/login/register.php">register</a> or hit your back button and try again!";
		exit;
		
		} else {
		
		if($num == 1) {
	setcookie("IamJim_user" , $user_name , time() + 3600);
	setcookie("IamJim_pass" , $password , time() + 3600);
	setcookie ("IamJim_user", $password,time()+3600);  
	
	header("Location: http://www.empiregaming.net/iamjim/");
	}
	
}
?>
Am I doing something wrong in creating the cookies?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

setcookie ("IamJim_user", $password,time()+3600);
a mix of the two previous lines?
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post by Jim »

I copied a line from PHP.net and filled in my own information. Just to see if my syntax was incorrect. :) That's what the third input is.
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

try using $_COOKIE['password'] instead of $password. and like-wise for any other variable you are attempting to pull out of a cookie.
Post Reply