我在打开网站时尝试输入密码,如果密码为true,它将重定向我到index.php,如果密码输入错误,它将让我再试一次。 但是为什么它返回内部错误500?
jquery-1.12.4.min.js:4 GET http://www.website.com/wp-content/themes/website/index.php 500 (Internal Server Error)
这是我的php代码(protect.php)
<?php
if( isset($_POST["password"])){
if ($_POST["password"] == "1234"){
header("Location:/wp-content/themes/website/index.php");
exit();
}
else{
echo "false";
}
}
这是我使用ajax(home.php)的表单。我认为这里是ajax底部的问题? :/
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css"
rel="stylesheet" id="bootstrap-css">
<link href="<?php echo get_template_directory_uri() .
'/css/websiteProtect.css'; ?>" rel="stylesheet">
<link href="<?php echo get_template_directory_uri() . '/css/bootstrap.min.css'; ?>" rel="stylesheet">
<!------ Include the above in your HEAD tag ---------->
<!-- All the files that are required -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<link href='http://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'>
<script src="<?php echo get_template_directory_uri() . '/js/vendor/jquery-1.12.4.min.js'; ?>"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<!-- Where all the magic happens -->
<!-- LOGIN FORM -->
<div class="text-center" style="padding:50px 0">
<div class="logo">Please enter password to browse site</div>
<!-- Main Form -->
<div class="login-form-1">
<form id="protect-form" name="protect-form" class="protect-form text-left" method="post">
<div class="login-form-main-message"></div>
<div class="main-login-form">
<div class="login-group">
<div class="form-group">
<label for="password" class="sr-only">Password</label>
<input type="password" class="form-control" id="password" name="password" placeholder="password">
</div>
<div class="form-group login-group-checkbox">
<input type="checkbox" id="lg_remember" name="lg_remember">
<label for="lg_remember">remember</label>
</div>
</div>
<button type="submit" class="login-button"><i class="fa fa-chevron-right"></i></button>
</div>
</form>
</div>
<!-- end:Main Form -->
</div>
<script>
/**
* Created by Faisal_pc on 4/9/2016.
*/
$(document).ready(function() {
$('#protect-form').validate({
rules: {
password: {
required: true
},
},
highlight: function(element) {
$(element).closest('.form-group').removeClass('success').addClass('error');
},
success: function(element) {
element.text('OK!').addClass('valid').closest('.form-group').removeClass('error').addClass('success');
},
submitHandler: function( form ) {
$.ajax({
url : '/wp-content/themes/website/protect.php',
data : $('#protect-form').serialize(),
type: "POST",
success : function(data){
console.log(data)
}
});
return false;
}
});
});
答案 0 :(得分:0)
尝试在header()函数中使用绝对方式。
位置:http://example.com/wp-content/themes/website/index.php
或$ _SERVER ['HTTP_HOST'],$ _ SERVER ['PHP_SELF']