user login with remember me option

Discussion in 'PHP' started by Kload, Mar 26, 2011.

  1. #1
    Ok now i want to create a user login box with a remember me checkbox, if a user checks the checkbox then it will store the value in a cookie else it will store in a session var not i am a newbie so how do i do that can anyone please explain?? my form is

    <form action="index.php" method="POST">
    <input name="user" type="text" size="32" />
    <input name="pass" type="text" size="32" />
    <input name="remember" type="checkbox" />
    <input type="submit" value="submit" />
    </form>
     
    Kload, Mar 26, 2011 IP
  2. Kload

    Kload Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    sorry if for got to post the php code

    <?php

    session_start();


    include realpath('init.php');
    include(BB_INC.'config.php');

    $bbuser = $_POST['user'];
    $bbpass = $_POST['pass'];
    $bbremember = $_POST['remember'];

    $user = stripslashes($user);
    $pass = stripslashes($pass);


    $login = sprintf("SELECT * FROM user WHERE user='%s' AND pass='%s'",
    mysql_escape_string($user), mysql_escape_string(md5($pass)));

    mysql_select_db($database_config, $config);
    $logged = mysql_query($login, $config) or die(mysql_error());

    $row_user = mysql_fetch_array($logged);

    if (mysql_num_rows($logged) == 0){
    header (sprintf("Location: ../login.php"));
    } else {
    if ($remember){
    setcookie("user", $user, time()+3600*24);
    header (sprintf("Location: ../index.php"));
    } else {
    $_SESSION['user'] = $user;
    header (sprintf("Location: ../index.php"));
    }
    }

    ?>
     
    Kload, Mar 27, 2011 IP
  3. Kload

    Kload Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ok i have solved the problem...
     
    Kload, Mar 27, 2011 IP