Page 1 of 1

PHP Code Cookies

Posted: Tue May 23, 2006 2:48 pm
by reecec
HI i need to change my code for rembering username loged in throught script as the way i have done i realise can be edited to view other peoples details

this is the way i did it when they loged in i made a link that said enter the link said enter.php?username=$user


so that the vairable user was following into the enter page so i could use it here like this :

Code: Select all

$userfromurl=$_GET['username'];

$sql="SELECT * FROM gameinfo WHERE username ='$userfromurl'";
so it got the SQL data for that user eg. enter.php?username=reece


but someone could jus change the username and view ther stuff


please could someone help do this in some other way

thanks reece

Posted: Tue May 23, 2006 3:08 pm
by Flamie
Well this might sound harsh but you're doing this totally the wrong way.
I'm assuming you have a table in your database with the users and their respective md5'd passwords.
So you need to have some sort of login form, where the users will input their username and password.
Then grab the data using your $_POST[] array, $_POST['username'] and $_POST['password'] and compare them to your database. If they match you have two ways of keeping track of the "login":
- either use a Session
-or use a cookie.

hope that helps!

Posted: Tue May 23, 2006 3:15 pm
by reecec
ye i have a login form and it checks the database that wasnt a way of loging on through the url that was just so my code new what username was loged in that is what i wanted to change


thanks reece

Posted: Tue May 23, 2006 3:17 pm
by Flamie
ok then use a cookie or a session :)

Cookies

Posted: Wed May 24, 2006 11:26 am
by reecec
hi


please could someone help with cookies

setcookie( "user", "$user", time()+7200, "/", "", 0 );



what if they want to log in to another account and it adds another cookie

as my sql rows is controled by the value user


so if they have 2 cookies with two differnt users it will load data for both


so i think i need another way to do this

thanks

reece