Ad

How Do I Make A Blank Page If Someone Directly Visits A .php Url

- 1 answer

I have form validation setup and working as you can see (using javascript), the only problem is that when someone successfully logs in, I have it redirect to login.php but if someone directly visits mysite.com/login.php they don't need a password to login. If there is any type of php code I need to add then that's fine, another option would be to change the function for the javascript on a successful login. Any info will help!

I have a password only form; here is my code:

<!doctype html>
<html>
<head>
<meta name="googlebot" content="noindex">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="js/account.js"></script>
<link rel="stylesheet" type="text/css" target="_blank" rel="nofollow noreferrer" href="css/main.css">
<meta charset="utf-8">
<title>The Order of Aztec</title>
</head>
<body>
<div id="page" align="center">
<br /><br /><br />
<div align="center"><img src="images/aztec-logo.png" width="256" height="198" alt="Aztec"/></div>
<br /><br /><br /><br /><br />
<div id="error-division"></div>
<br />
<form id="myForm" align="center">
<div align="center"><input placeholder="Password" name="pword" id="pword" type="password" /></div>
<br />
<div align="center" id="agree-box"><input id="agree-box-input" onClick="login();return false;" type="checkbox">Agree that you are part of the steam group "The order of aztec."</input></div>
<br />
<div align="center"><input id="submit" type="submit" /></div>
</form>
<div id="ack"></div>
</div>
</body>
<script type="text/javascript">
function login()
{
var pass = document.getElementById('pword');

var corpass = "t";

var agree = document.getElementById('agree-box-input');

if(pass.value == corpass && agree.checked == true)
{
window.location = "login.php"
} else {
document.getElementById("error-division").innerHTML = "Wrong password or             agreement not checked. Please try again.";
}
}
</script>
</html>
Ad

Answer

add if statement in your login.php

<?php

if(isset($_POST['your_username']) && isset($_POST['your_password'])){
   // do your activities
}else{ ?>
   <script type="Javascript">
      alert("Your username / password is incorrect");
      window.location = "your_validation_page.php";
   </script>

<?php } ?>
Ad
source: stackoverflow.com
Ad