Search code examples
phpmysqlsmarty

how to view the cookies value in my login page?


I have worked on "keep me logged in" in my login page in smarty. I want to view the email and password on my login page after login and i have some problem because cookies value are always store in my browser but not viewing in my login page.

my php code are:

if (isset($_REQUEST['login'])) {

    // $email=$_REQUEST['email'];
    // $pass=$_REQUEST['pass'];

    if (isset($_REQUEST['keeplogin'])) {
        setcookie("Email", $_REQUEST['email'], time() + 3600);
        setcookie("Pass", $_REQUEST['pass'], time() + 3600);
        $email = $_COOKIE['Email'];
        $pass = $_COOKIE['Pass'];
    }

    $smarty->assign('email', $email);
    $smarty->assign('pass', $pass);
}

and my login page

<form role="form" action="index.php" method="post" enctype="multipart/form-data">
    <div class="form-group">
        <label for="pwd">Email ID:</label>
        <input class="form-control" type="email" placeholder="[email protected]" name="email" value="{$smarty.cookies.$email}" required="required" />
    </div>
    <div class="form-group">
        <label for="pwd">Password:</label>
        <input class="form-control" type="password" name="pass" value="{$pass}" required="required" />
        <h5 align="right"><a href="index.php?act=add_forgot_password">Forgot Password<span class="badge"></span></a></h5>

    </div>

    <div class="login button">
        <input type="submit" class="btn btn-primary" name="login" value="Login" style="width:100%; height:40px;" />
    </div>

    <p class="keeplogin">
        <input type="checkbox" name="keeplogin" id="loginkeeping" value="keep_login" />
        <label for="loginkeeping">Keep me logged in</label>
    </p>
    <input type="hidden" name="act" value="{$act}" />
    <input type="hidden" name="u_id" value="{$u_id}" />
</form>

how to view a email and password with smarty in login page?


Solution

  • You can get cookie value in php like this

    echo "<b>Email:</b>".$_COOKIE['Email'];
    echo "<b>Pass:</b>".$_COOKIE['Pass'];