Jump to content

[SOLVED] PHP else if


sheep01

Recommended Posts

<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 :P

 

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

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

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

<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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.