View Single Post
Old Feb 19th, 2008, 8:08 PM   #4
MrMan9879
Programmer
 
MrMan9879's Avatar
 
Join Date: Sep 2005
Location: Nanaimo, BC, Canada
Posts: 95
Rep Power: 0 MrMan9879 is an unknown quantity at this point
Send a message via MSN to MrMan9879
Re: Sessions Problem

Alright, so now I'm working on the actual authentication script for my website, and I'm using cookies. I tested out cookies, and I had them working, but now when I try it, it isn't working.

Here is my code:

while ($result=mysql_fetch_array($query)) {
		//loop through the usernames and passwords
		if (($new_user == $result['username']) && ($new_password == $result['password'])) {
			//if the user matches a user in the database, setup the cookies
			setcookie('user_name', $new_user, time()+3600);
			setcookie('password', $new_password, time()+3600);

			//create the session variables
			$_SESSION['user_name'] = $_COOKIE['user_name'];
			$_SESSION['password'] = $_COOKIE['password'];
			
			print_r($_SESSION);
			print_r($_COOKIE);
			
			//create normal variables
			$user = $_SESSION['user_name'];
			$password = $_SESSION['password'];
			
			//end the loop
			break;
		}
	}

I basically just have it looping through a mysql query looking to match a username and password, and then it puts it into a cookie, then a session cookie and a variable. It wasn't working, so I used print_r to view what's in the $_SESSION and $_COOKIE global array, but there was nothing in it.

Any thoughts on why exactly it doesn't work?
MrMan9879 is offline   Reply With Quote