Remeber me Option in Codeigniter::
#Set Cookie
if(isset($posted['rememberme']) && ($posted['rememberme'] == 'on' || $posted['rememberme']) ){
$cookie_prefix = 'stack_';
$user_cookie = array(
'name' => 'uname',
'value' => $posted['username'],
'expire' => '86400',
'domain' => '',
'path' => '/',
'prefix' => $cookie_prefix,
);
$this->input->set_cookie($user_cookie);
$pwd_cookie = array(
'name' => 'pwd',
'value' => $posted['password'],
'expire' => '86400',
'domain' => '',
'path' => '/',
'prefix' => $cookie_prefix,
);
$this->input->set_cookie($pwd_cookie);
}else {
delete_cookie("stack_uname");
delete_cookie("stack_pwd");
}
#For Get The Cookie data::
$getCookie_username = $this->input->cookie('stack_uname');
$getCookie_password = $this->input->cookie('stack_pwd');
#HTML FORM::
<div class="form-group has-feedback">
<input type="text" class="form-control" placeholder="Username" name="username" value= "<?=$getCookie_username;?>" >
<span class="glyphicon glyphicon-user form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="password" class="form-control" placeholder="Password" name="password" value= "<?=getCookie_password;?>" >
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="row">
<div class="col-xs-8">
<div class="checkbox icheck">
<label>
<input type="checkbox" name="rememberme" value="1" <?=($rememberme['is_remembered']) ? 'checked' : '' ?> > Remember Me
</label>
</div>
</div>
<div class="col-xs-4">
<button type="submit" name="signin" class="btn btn-primary btn-block btn-flat">Sign In</button>
</div>
</div>
#Set Cookie
if(isset($posted['rememberme']) && ($posted['rememberme'] == 'on' || $posted['rememberme']) ){
$cookie_prefix = 'stack_';
$user_cookie = array(
'name' => 'uname',
'value' => $posted['username'],
'expire' => '86400',
'domain' => '',
'path' => '/',
'prefix' => $cookie_prefix,
);
$this->input->set_cookie($user_cookie);
$pwd_cookie = array(
'name' => 'pwd',
'value' => $posted['password'],
'expire' => '86400',
'domain' => '',
'path' => '/',
'prefix' => $cookie_prefix,
);
$this->input->set_cookie($pwd_cookie);
}else {
delete_cookie("stack_uname");
delete_cookie("stack_pwd");
}
#For Get The Cookie data::
$getCookie_username = $this->input->cookie('stack_uname');
$getCookie_password = $this->input->cookie('stack_pwd');
#HTML FORM::
<div class="form-group has-feedback">
<input type="text" class="form-control" placeholder="Username" name="username" value= "<?=$getCookie_username;?>" >
<span class="glyphicon glyphicon-user form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="password" class="form-control" placeholder="Password" name="password" value= "<?=getCookie_password;?>" >
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="row">
<div class="col-xs-8">
<div class="checkbox icheck">
<label>
<input type="checkbox" name="rememberme" value="1" <?=($rememberme['is_remembered']) ? 'checked' : '' ?> > Remember Me
</label>
</div>
</div>
<div class="col-xs-4">
<button type="submit" name="signin" class="btn btn-primary btn-block btn-flat">Sign In</button>
</div>
</div>
No comments:
Post a Comment