|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
I have a basic authentication script using PHP to verify username & password from a MySQL db. How could I make it so the users would not need to login everytime and a cookie could just save their info?
__________________
![]() ![]() "Only Linux users see the end of crashes." - Pl4t0 |
|
#2
|
|||
|
|||
|
ive never tried to program username remebers using cookies before, but im guessing it would go something like this
when the user is accepted by the submit form, if the password and username is checked and passed, a cookie is created with the usernames 'name' (hehe bad joke!) when the comeback to the login form again, in the header of the script check to see if theres a cookie, if so check the value of the cookie against the database, if correct, auto login! anyways thats how i would do it, if you wanted to be more secure you could encrypt the password, and store that as a cookie as well |
|
#3
|
|||
|
|||
|
Hi,
Ben's right, and here's the code you need. Firstly, for the login form: <?php global $HTTP_COOKIE_VARS; if($HTTP_COOKIE_VARS["auth"] == true) { header("some_other_page.php"); } else { ?> <form action="checklogin.php" method="post"> User: <input type="text" name="user"><br> Password <input type="password" name="pass"><br> <input type="submit"> <?php } ?> and for checklogin.php: // do you database stuff here, i will assume you've created // a variable called $ok which is the result of a call to // mysql_num_rows("select * from logins where user=...") etc if($ok == true) { setcookie("auth", true); header("some_other_page.php"); } else { header("location: login.php"); } that should get you started, let me know if you need more help |
|
#4
|
|||
|
|||
|
thx for the code, i'll try it
![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Programming Tools > Using cookies with forms |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|