El Estrago Posted May 29, 2011 Share Posted May 29, 2011 I'm looking for a (good) php script which password protects a certain part of the page. This is what I've got: <?php $username = "username"; $password = "password"; if ($_POST['txtUsername']!= $username ¦¦ $_POST['txtPassword']!= $password) { ?> <form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> Username: <input type="text" name="txtUsername" /> Password: <input type="password" name="txtPassword" /> <input type="submit" value="Submit" /> </form> //else bit <?php } else { ?> <p> passworded bit </p> <?php } ?> Problem: it doesn't work. I think it has got something to do with the if/else-part. Quote Link to comment https://forums.phpfreaks.com/topic/237803-password-protect-a-certain-part-of-the-page/ Share on other sites More sharing options...
seanlim Posted May 29, 2011 Share Posted May 29, 2011 Replace the if statement with: if (!isset($_POST['txtUsername']) || !isset($_POST['txtPassword']) || $_POST['txtUsername']!= $username || $_POST['txtPassword']!= $password) { You have to check if the variables are even set in the first place, and also, your pipe character seems funny... Quote Link to comment https://forums.phpfreaks.com/topic/237803-password-protect-a-certain-part-of-the-page/#findComment-1221994 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.