sheep01 Posted May 18, 2008 Share Posted May 18, 2008 <form action="/check.php" method=POST> Password: <input type=password name=passwd size=25> <br> <input type=submit value='Submit'> </form> Below is check.php <?php $passwd = $HTTP_POST_VARS['passwd']; if($passwd == "cow"){ include 'http://www.Sheep01.com/include/waffles.php'; } else { echo "If you do not know the password, you need to LEAVE."; } ?> This can be seen on http://www.sheep01.com/waffles Password is cow as im sure you know That little snippet does not work, It includes the proxy page but once I enter any data into the page, it echos the else. Why is this? Link to comment https://forums.phpfreaks.com/topic/106120-solved-php-else-if/ Share on other sites More sharing options...
play_ Posted May 18, 2008 Share Posted May 18, 2008 You include waffles.php inside check.php and when you submit the form in waffles.php, there is no $_POST['passwd'] for check.php to check. Try validating on the same page. Make the form action <?php echo $_SERVER['php_self']; ?> and change the code to this. <?php $passwd = $HTTP_POST_VARS['passwd']; // this is old. use it unless you're using an old version of php if($passwd == "cow"){ header('Location: http://www.Sheep01.com/include/waffles.php'); } else { echo "If you do not know the password, you need to LEAVE."; include('./include/footer.php'); exit(); } } Link to comment https://forums.phpfreaks.com/topic/106120-solved-php-else-if/#findComment-543887 Share on other sites More sharing options...
sheep01 Posted May 18, 2008 Author Share Posted May 18, 2008 The second block of code is the entire contents of check.php Link to comment https://forums.phpfreaks.com/topic/106120-solved-php-else-if/#findComment-543889 Share on other sites More sharing options...
garry Posted May 18, 2008 Share Posted May 18, 2008 You need to put a hidden field in the form called "submitted" and set it to 1. Then you can put at the top of the page: <?php if (isset($_POST['submitted'])) { // Put the form action here } else { $passwd = $HTTP_POST_VARS['passwd']; if($passwd == "cow"){ include 'http://www.Sheep01.com/include/waffles.php'; } else { echo "If you do not know the password, you need to LEAVE."; } } ?> Link to comment https://forums.phpfreaks.com/topic/106120-solved-php-else-if/#findComment-543890 Share on other sites More sharing options...
ballhogjoni Posted May 18, 2008 Share Posted May 18, 2008 worked for me Link to comment https://forums.phpfreaks.com/topic/106120-solved-php-else-if/#findComment-543893 Share on other sites More sharing options...
sheep01 Posted May 18, 2008 Author Share Posted May 18, 2008 <form action=""<?php echo $_SERVER['php_self']; ?>"" method=POST> Password: <input type=password name=passwd size=25> <br> <input type=submit value='Submit'> </form> <?php $passwd = $HTTP_POST_VARS['passwd']; // this is old. use it unless you're using an old version of php if($passwd == "cow"){ header('Location: http://www.Sheep01.com/include/waffles.php'); } else { echo "If you do not know the password, you need to LEAVE."; } ?> Now it looks like this: www.sheep01.com/test And Im using PHP4, if that helps. Link to comment https://forums.phpfreaks.com/topic/106120-solved-php-else-if/#findComment-543913 Share on other sites More sharing options...
Goldeneye Posted May 18, 2008 Share Posted May 18, 2008 You need to put that HTML Form after the header(). <?php if(isset($_POST['submit'])) // The Submit Button was pressed. The value 'submit' was identified in the HTML form with: name='submit' { if($_POST['passwd'] == "cow") // $_POST['passwd'] is what the user submitted as the password { header('Location: http://www.Sheep01.com/include/waffles.php'); } else { echo "If you do not know the password, you need to LEAVE."; } } else // The Submit was not pressed { ?> <form action="<?php echo $_SERVER['php_self']; ?>" method=POST> Password: <input type=password name=passwd size=25> <br> <input type=submit value='Submit' name='submit'> </form> <?php } // This Curly Brace simply ends the 'else' statement ?> Hopefully, that works. Link to comment https://forums.phpfreaks.com/topic/106120-solved-php-else-if/#findComment-543982 Share on other sites More sharing options...
play_ Posted May 18, 2008 Share Posted May 18, 2008 put this at the very top of your page.. right after the php tags <?php ob_start(); make sure there are no white spaces or any other characters before ob_start. put this at the end of your script ob_end_flush(); ?> Link to comment https://forums.phpfreaks.com/topic/106120-solved-php-else-if/#findComment-543987 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.