设计用PHP编写的门户网站的登录页面并使用mysql。不知何故,我输入正确的细节后的javascript没有被执行。以下是代码:
<?php
include_once dirname(dirname(__FILE__))."/const.php";
include_once PHP_PATH.'/config.php';
//Logic to validate login details
if(isset($_POST ['Login']))
{
//Start your session
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
// Connect to database
$username ='';
$password ='';
if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1800)) {
// last request was more than 30 minutes ago
session_unset(); // unset $_SESSION variable for the run-time
session_destroy(); // destroy session data in storage header("location:logout.php"); }
if (!isset($_SESSION['CREATED'])) {
$_SESSION['CREATED'] = time();
} else if (time() - $_SESSION['CREATED'] > 1800) {
// session started more than 30 minutes ago
session_regenerate_id(true); // change session ID for the current session and invalidate old session ID
$_SESSION['CREATED'] = time(); // update creation time
}
// Assign local variables to posted data
$username = trim($_POST['uname']);
$password = trim($_POST['password']);
$username = stripslashes($username);
$password = stripcslashes($password);
$md5_password = md5($password);
$query = "SELECT f_name, active,pk_user_id FROM tbl_users WHERE email ='$username' and password ='$md5_password'";
$data=mysqli_query($conn,$query)or die(mysqli_error($conn));
mysqli_close($conn);
if(!empty($row=mysqli_fetch_array($data))){
if ($row[1]!=0){
$seconds = 60*30 + time();
setcookie(loggedin, date("F js - g:i a"), $seconds);
$_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp
//Store the name in the session
$_SESSION['username'] = $username;
$_SESSION['name'] = $row[0];
$_SESSION['pk_user_id'] = $row[2];
//echo $row[0];
//echo 'Login successful';
header("location:login_success.php");
}else{
?>
<script type="text/javascript">
history.back();
alert("Please verify your account before login");
</script>
<?php
}
} elseif(empty ($username)or empty ($password)){
?>
<script type="text/javascript">
history.back();
alert("Please enter Username and Password");
</script>
<?php
}
else{
?>
<script type="text/javascript">
history.back();
alert("Incorrect Login Details");
</script>
<?php
}
}
}
?>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>login</title>
<!-- CSS -->
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto:400,100,300,500">
<link rel="stylesheet" href="<?=ASSET_PATH?>bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="<?=ASSET_PATH?>font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="<?=ASSET_PATH?>css/form-elements.css">
<link rel="stylesheet" href="<?=ASSET_PATH?>css/style.css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<!-- Favicon and touch icons -->
<link rel="shortcut icon" href="<?=ASSET_PATH?>ico/favicon.png">
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="<?=ASSET_PATH?>ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="<?=ASSET_PATH?>ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="<?=ASSET_PATH?>ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="<?=ASSET_PATH?>ico/apple-touch-icon-57-precomposed.png">
</head>
<body>
<form name="Home" action="index.php" class="login-form" method ="POST">
<!-- Top content -->
<div class="top-content">
<div class="inner-bg">
<div class="container">
<div class="row">
<div class="col-sm-8 col-sm-offset-2 text">
<h1><strong>Gurukul</strong> Student Portal</h1>
<div><big><label style="font-family: Comic Sans MS;">New User?</label><span style="font-family: Comic Sans MS;"> </span><a style="font-family: Comic Sans MS; color: red;" href="register_form.php" target="_blank">Click here</a></big> to Register
<div class="description">
<p>
Please enter your credentials below:
</p>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6 col-sm-offset-3 form-box">
<div class="form-top">
<div class="form-top-left">
<h3>Login to our site</h3>
<p>Enter your username and password to log on:</p>
</div>
<div class="form-top-right">
<i class="fa fa-lock"></i>
</div>
</div>
<div class="form-bottom">
<div class="form-group">
<label class="sr-only" for="uname">Username</label>
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input type="text" name="uname" placeholder="Username..." class="form-username form-control" id="uname">
</div>
<a href="forgot_username.php">Forgot Username ?</a>
</div>
<div class="form-group">
<label class="sr-only" for="form-password">Password</label>
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
<input type="password" name="password" placeholder="Password..." class="form-password form-control" id="password">
</div>
<a href="forgot_pwd_form.php">Forgot password ?</a>
</div>
<button name="Login" type="submit" class="btn">Sign in!</button>
<button name="Cancel" type="reset" class="btn">Cancel</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
<!-- Javascript -->
<script src="<?=ASSET_PATH?>js/jquery-1.11.1.min.js"></script>
<script src="<?=ASSET_PATH?>bootstrap/js/bootstrap.min.js"></script>
<script src="<?=ASSET_PATH?>js/jquery.backstretch.min.js"></script>
<script src="<?=ASSET_PATH?>js/scripts.js"></script>
<!--[if lt IE 10]>
<script src="<?=ASSET_PATH?>js/placeholder.js"></script>
<![endif]-->
</body>
</html
配置文件包含正确的数据库详细信息,并且常量文件包含路径也正在正确执行。输入正确的详细信息后,页面只需刷新并保持在同一页面上。我试过检查控制台,但它没有显示任何响应。不知道我哪里错了。
答案 0 :(得分:2)
你的Javascript是 - 不是 - <HTML></HTML>
内部。
这就是 - 没有 - 执行的原因。