I try to enter password when I open website, if the password true it will redirect me to the index.php, if the pass wrong it will let me try again. But why does it return internal error 500 ?
jquery-1.12.4.min.js:4 GET http://www.website.com/wp-content/themes/website/index.php 500 (Internal Server Error)
This is my php code (protect.php)
<?php
if( isset($_POST["password"])){
if ($_POST["password"] == "1234"){
header("Location:/wp-content/themes/website/index.php");
exit();
}
else{
echo "false";
}
}
and this is my form with ajax (home.php). I think the problem here at the bottom in 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;
}
});
});