I started developing this very simple PHP login that asks for a password to access a website. It also creates a cookie, allowing access to continue until the user closes his browser window.
At the top of each page, I check the cookie:
<?php if(!isset($_COOKIE['authorised']) || ($_COOKIE['authorised'] != 'true')) { include('login.php'); exit; } ?>
If they do not, I will exit and show the login form:
<?php function pageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") { $pageURL .= "s"; } $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } $pageRedirect = pageURL(); if(isset($_POST['password']) && ($_POST['password'] == 'qwe123')) { setcookie('authorised', 'true'); header("Location:$pageRedirect",303); } else { include('noaccess.php'); exit; } ?> <form action="<?php echo pageURL(); ?>" method="post"> <input type="password" name="password" /> <input type="submit" title="I agree" value="I agree" name="submit" /> </form>
The current PHP from the old Warning page, when you need to agree to access the site, I want to change it to work with a simple form, so that if the user enters a password, for example, "qwe123", they create a cookie, and then are redirected back to page, but now have access due to cookies. If they are mistaken, another page is included and completed.
Can someone help me? Thanks
source share