<?php
if(isset($_SESSION['id'])==null){
header("Location: login.html");
}
?>
<script>
$(function(){
$(document).on("click", ".button", function(e) {
e.preventDefault();
{
//This will capture all the inputs from the form
var infom = $("#myform").serialize();
//$("#showresult").addClass('loader');
$.ajax({
beforeSend: function() { },
type: "POST",
url: "login.php",
data:infom,
success: function(result){
//$("#showresult").removeClass('loader');
$('#showresult').html(result);
}
});
e.preventDefault();
}
});
});
</script>
在login.php文件中,我放置了它,但它不做任何事情,用户仍然可以在浏览器导航中放入login.php,仍然可以访问它。我想阻止他们这么做。我希望该文件只在我尝试登录登录html页面时调用。上面是用于显示错误消息(如果有的话)的ajax代码。当我将它与if post或HTTP reference结合使用时,它会重定向到一个持续加载的空白页面。
你可以用这个
if($_SERVER['HTTP_REFERER']=="complete URL/login.html")
url必须是http://www.example.com/login.html
,如果你是从login提交表单,你必须检查$_POST。
login.php
// check if form has been submitted
IF (!isset($_POST)) {
Header('Location: login.html');
die();
}