我有一个PHP文件“login.php”这是使用js在html中调用,但元素不会将变量传递给另一个php文件“ucheck_com.php”它将执行验证等等是否有另一种方法做这个?
sample.html:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
</head>
<body>
<div id="displaylogin"></div>
</body>
</html>
<script>
$(document).ready(function() {
$(function(){
$("#displaylogin").load("user/login.php");
});
});
</script>
login.php中:
<?php
require_once 'userphp/connect.php';
require_once 'userphp/ucheck_com.php';
require_once 'userphp/errors.php';
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" lang="en-US">
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<title></title>
</head>
<body>
<div class="page-container">
<form action="" method="post" class="main">
<label>Alias</label>
<input type="text" name="alias" value="">
<label>Password</label>
<input type="password" name="password">
<br />
<input type="submit" name="login_user" id="login_user" value="Login">
</form>
</div>
</body>
</html>
ucheck_com.php:
if (isset($_POST['login_user'])) {
$alias = mysqli_real_escape_string($connect, $_POST['alias']);
$password = mysqli_real_escape_string($connect, $_POST['password']);
$_SESSION['alias'] = $alias;
$_SESSION['password'] = $password;
if (empty($_SESSION['alias'])) {
array_push($errors, "Alias is required");
}
if (empty($_SESSION['password'])) {
array_push($errors, "Password is required");
}
if(count($errors) == 0) {
$result = mysqli_query($connect, "SELECT * FROM `user` WHERE `alias` = '$alias' AND `password` = '$password'");
foreach ($result as $item) {
$_SESSION['email_add'] = $item['email_add'];
$_SESSION['user_id'] = $item['user_id'];
}
$row_cnt = mysqli_num_rows($result);
if($row_cnt == 1) {
header("location: ../index.html");
} else {
array_push($errors, "Wrong alias/password combination");
}
}
}
当您使用$_SESSION
时,您需要以下列方式打开会话:
session_start();