Forum Moderators: coopster

Message Too Old, No Replies

PHP Login remember username and pass

site login with remember me function

         

neebski

11:05 pm on Aug 14, 2007 (gmt 0)

10+ Year Member



Hey there, I currently have a login to my website that works great BUT I would really like to have a cookie remember the username and password so next time the user wants to login they can simply just click login. I do not wish to have the system auto-log them in. If you want to take a look at my current login pages code let me know.

Thanks!
- Kevin Neberman

eelixduppy

11:12 pm on Aug 14, 2007 (gmt 0)



Hello and Welcome to WebmasterWorld!

To set cookies you can use the setcookie [php.net] function.

Once the cookie is set, you can do something like this for the username input field:


<input type="text" name="username" value="<?php echo (isset($_COOKIE['username']))?$_COOKIE['username']:'';?>" />

Try that out and see where you get. By the way, the above uses the ternary operator: [php.net...]

neebski

11:21 pm on Aug 14, 2007 (gmt 0)

10+ Year Member



I set cookie by?

So in the end both fields would be

<input type="text" name="username" value="<?php echo (isset($_COOKIE['username']))?$_COOKIE['username']:'';?>" />
<input type="text" name="password" value="<?php echo (isset($_COOKIE['password']))?$_COOKIE['password']:'';?>" />

Thanks!

neebski

11:38 pm on Aug 14, 2007 (gmt 0)

10+ Year Member



I just tried

<?php
$value = 'mysite';
setcookie(username,$row_user['username'],)
setcookie(password,$row_user['password'],)
?>

this is on a page that has session data on it already so I was hoping that I could throw in the session data for username and password from the database but it didn't seem to work..

eelixduppy

4:02 am on Aug 15, 2007 (gmt 0)



Try something like this to set the cookies:

setcookie("username", $row_user['username'], time()+36000);
setcookie("password", $row_user['password'], time()+36000);

Try the above and see what you get.