Author: Sun Sports
In PHP, the simplest conditional statement is in the form of an "if" statement, which is generally as follows:
--------------------------------------------------------------------------------
if (condition)
{
Do this!
}
--------------------------------------------------------------------------------
The "condition" here is a description of the condition, and PHP is judged to derive any value of "true" or "false". If it is true, all of the PHP code in the braces will be executed, and conversely, if the code in the braces is false, then the line after the "if" statement structure block will continue to be executed.
We'll show you how the "if" statement works by adding an example of identity authentication to the "login.php" script above. Access is allowed only if the user name entered is "Neo".
--------------------------------------------------------------------------------
< html>
< head>
< Basefont face= "song Body" >
< body>
< center>
<?
Check the name and feedback the appropriate information
if ($name = = "Neo")
{
?>
< font face= "Arial" size= "-1" >
Welcome into the Matrix Neo.
< p>
Maybe it was the force that forced you to do it,,, Oh, improper film! </FONT>
<?
}
?>
<?
If the password is wrong,
if ($name! = "Neo")
{
?>
< font face= "Arial" size= "-1" >
I wonder if you've ever heard of Shakespeare, <? Echo $name;
< p>
He demanded a bouquet of roses for another name, because that bundle might smell more fragrant.
< p>
For you, unfortunately, I disagree. Refuse to enter!
</FONT>
<?
}
?>
</center>
</body>
--------------------------------------------------------------------------------
In this case, the "if" statement feeds back the two information by judging whether the password entered is correct. PHP also allows you to "nest" conditional statements-for example, this is a valid PHP code:
--------------------------------------------------------------------------------
<?
if ($day = = "Thursday")
{
if ($time = = "12")
{
if ($place = = "Italy")
{
$lunch = "pasta";
}
}
}
?>
http://www.bkjia.com/PHPjc/316405.html www.bkjia.com true http://www.bkjia.com/PHPjc/316405.html techarticle Author: Sun Movement in PHP, the simplest form of conditional statements is the IF statement, which is generally as follows:---------------------------------------------------------------------- ----------...