Hi,
first post and first toe in the water with PHP.
I’m testing a simple password protection webpage. I have two files in the public folder - one the password script (http://www.provision-cctv.com/passtest.php) the other the file i want to protect.
The passtest file has the following:-
<?php session_start() ?> Untitled Document <?php if (array_key_exists('ewTest' , $_POST)) { $username = trim($_POST['username']); $_SESSION['username'] = $username; $password = trim($_POST['password']); $_SESSION['password'] = $password; if (($username == "Pink") && ($password == "Elephant")) { $response = "You're welcome! Enter Here"; } else { $response = "Sorry, you do not have permission to access this webpage!"; } } ?> #wrapper { width: 250px; padding: 20px; margin: 20px auto; background-color:#CCC; font-family: verdana, arial, helvetica, sans-serif; font-size: 11px; } #wrapper p { margin: 0 0 0 0; padding: 0; text-align: center; } input { width: 250px; } input#submit { width: 100px; margin: 15px 0 0 0; }Please enter your Username & Password below. (Case sensitive)
UsernamePassword
<?php if(isset($response)) echo $response;?>
The file I’m trying to protect is (http://www.provision-cctv.com/CFS2 and the first lines of code on this page start:-
<?php session_start() ?> <?php if (!isset($_SESSION['username']) && !isset($_SESSION['password'])) { header("Location: http://www.provision-cctv.com/passtest.php"); } if (isset($_SESSION['username'])) { unset($_SESSION['username']); session_destroy(); } if (isset($_SESSION['password'])) { unset($_SESSION['password']); session_destroy(); } ?>So in theory I guess that if someone tries to open the CFS2 file the log-in/password box should open it first - but there is no security - you go straight in!
If i open up the pass test file in a browser - enter the log-in and password then i can open the CFS2 file - but surly that’s not how it should work?
Am I losing the plot?
Many thanks.