用户名和密码未在Cookie

时间:2015-09-15 10:14:18

标签: php html mysql cookies

我想设置用户名和密码,检查记住我复选框并取消勾选复选框但当我点击记住我复选框并检查cookie的输出然后没有设置cookie(没有输出) )。我想显示我的代码请检查并告诉我我在哪里犯了错误:

<div class="col-md-5">
	<h4>Login</h4>
	<form  method="post" action="" name="customer_form">   
		<?php 
			if($danger_msg_client){
			
				?>
				<div class="alert alert-danger">
					<strong><?php echo $danger_msg_client;?></strong>
				</div>
				<?php
			}
		?>
		<div class="form-group">
			<div class="input-group"> <span class="input-group-addon"><i class="fa fa-user"></i></span>
				<input type="text" class="form-control" name="client_username" id="client_username" placeholder="Email ID" required="required" value="<?php echo $_COOKIE['username']; ?>"/>
			</div>
		</div>
		<div class="form-group">
			<div class="input-group"> <span class="input-group-addon"><i class="fa fa-lock"></i></span>
				<input type="password" class="form-control" name="client_password" id="client_password" placeholder="Password" required="required" value="<?php echo $_COOKIE['password']; ?>"/>
			</div>
		</div>
		<br/>
		<a href="client/forgot-password.php" class="pull-right"><i class="icon-question-sign"></i>&nbsp;Forgot Password</a>
		<label>
			<input type="checkbox" name="client_remember" id="client_remember" class="btn btn-mini custom-checkbox active" value="1"
			<?php 
				if(isset($_COOKIE['username']) && isset($_COOKIE['password'])) {
					echo 'checked="checked"';
				}
				else {
					echo '';
				}
			?> >
			&nbsp;&nbsp;&nbsp;Remember Me
		</label>
		<input type="submit" name="customer_submit" id="customer_submit" value="LogIn" class="btn btn-success col-md-offset-5"/>
	</form>
</div>

session_start();    
print_R($_COOKIE);
include('inc/header.php');
//error_reporting(0);
include("agent_database.php");  
if (isset($_POST['customer_submit'])){  

    if ($_SESSION['email'] == $email_input && $_SESSION['password'] == $password_input){

        if(isset($_POST['client_remember']) == 1){

            echo "munesh";
            setcookie('username', $_POST['client_username'], time()+60*60*24*365);
            setcookie('password', $_POST['client_password'], time()+60*60*24*365);

        }else{

            echo "chaudhary";
            setcookie('username', $_POST['client_username'], false);
            setcookie('password', $_POST['client_password'], false);
        }               
        if($result_two > 0){

            $_SESSION['flag'] = true; 
            //echo '<script>location.href="client/dashboard/my-account.php"</script>';          
        }
    }
    $email_input = $_POST['client_username'];
    $client_remember = $_POST['client_remember'];
    $_SESSION['my_email'] = $_POST['client_username'];
    $_SESSION['my_password'] = $_POST['client_password'];
    $password_input = md5($_POST['client_password']); 
    $sql = "SELECT email, password, status FROM customer_regis WHERE email='".$email_input."' && password='".$password_input."' && status = 1 ";
    $result=mysql_query($sql);
    $result_two = mysql_num_rows($result);
    $row = mysql_fetch_assoc($result);
    //echo "<pre>"; print_r($row)."</br>";  
    $_SESSION['email'] = $row['email'];
    $_SESSION['password'] = $row['password'];
    else{

        $danger_msg_client = "please enter a correct email and password!";
    }

}  

2 个答案:

答案 0 :(得分:3)

存储在cookies中的密码..:/:/:/ ?????? 使用会话..

答案 1 :(得分:-1)

检查此网址。这可能很有用。 http://www.bitrepository.com/php-autologin.html