写的登陆页面一直无法跳转到欢迎界面,大佬看下哪里不对。点击登陆还是显示登陆框,没有预想的欢迎语句。感觉可能是session的使用出了问题,但是查不出来。首页<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>ecshop</title> <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script></head><div class="container"> <div class="row clearfix"> <div class="col-md-8 column"> <div class="page-header"> <h1> ECSHOP </h1> </div> </div> <div class="col-md-4 column"> <?php // 引入 functions.php 文件 require_once("loginfunction.php"); //登录状态显示用户名,未登录显示登录表单 $loginfc = new indexlogin(); $loginfc->loggedIn(); ?> </div> </div>loginfunction<?phpclass indexlogin{function loggedIn(){ //通过 $_SESSION 来判断用户是否登录 if(empty($loggd)){ echo<<<LOG <form class="form-horizontal" method="post" action="loginaction.php"> ID<input type="text" class="form-control" name="id"><br> Password <input type="password" class="form-control" name="pass"><br> <input type="submit" value="ログイン"> </form>LOG; }else{ // 登录显示欢迎页面 echo 'Welcome, ' . $loggd; echo <<<BUT <input type="button" value="logout" onclick="logoutFunction()">BUT; } } }?>loginaction<?php$user = "r.ko";$password = "123";$id = $_POST['id'];$pass = $_POST['pass']; $dbh = new PDO('mysql:host=localhost;dbname=user;charset=utf8', $user, $password); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "select pass FROM id where id =" .$id; $stmt = $dbh->query($sql); $result = $stmt->fetchAll(PDO::FETCH_ASSOC) ; $url = "http://localhost/boot/index.php"; if(!empty($result)){ if($pass == $result[0]['pass']){ $_SESSION["id"] = $id; $_SESSION["loggd"] = 1; echo "<script language = 'javascript'type = 'text/javascript'>";echo " window.location.href = '$url' "; echo "</script>"; }else{ echo<<<LOW <div class="alert alert-danger" role="alert"> <a href="$url" class="alert-link">PASSERR TRY AGAIN</a> </div>LOW; }} else { echo<<<LOF <div class="alert alert-danger" role="alert"> <a href="$url" class="alert-link">ERR TRY AGAIN</a> </div>LOF; } $dbh = null;?>
添加回答
举报
0/150
提交
取消