PHP Code Cookies

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
reecec
Forum Contributor
Posts: 218
Joined: Sun Apr 02, 2006 7:12 am

PHP Code Cookies

Post 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
Last edited by reecec on Wed May 24, 2006 12:48 pm, edited 1 time in total.
Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

Post 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!
reecec
Forum Contributor
Posts: 218
Joined: Sun Apr 02, 2006 7:12 am

Post 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
Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

Post by Flamie »

ok then use a cookie or a session :)
reecec
Forum Contributor
Posts: 218
Joined: Sun Apr 02, 2006 7:12 am

Cookies

Post 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
Post Reply