PHP4 practical application experience (3 ). Author: Sun Sports in PHP, the simplest form of condition statement is the if statement, generally as follows: -------------------------------------------------------------------------------- author: Sun Sports
In PHP, the simplest condition statement is an "if" statement, which is generally as follows:
--------------------------------------------------------------------------------
If (condition)
{
Do this!
}
--------------------------------------------------------------------------------
Here, the "condition" is a condition description. after PHP judges, it will produce any value of "true" or "false. If it is a true value, all PHP code in the large arc will be executed. On the contrary, if it is a false value, the code in the large arc will be ignored, continue to execute the rows after the "if" statement structure block.
We will add an authentication example to the above "login. php" script to demonstrate how the "if" statement works. Access is allowed only when the user's user name is "neo.
--------------------------------------------------------------------------------
<Html>
<Head>
<Basefont face = "">
</Head>
<Body>
<Center>
<?
// Check the name and feedback the corresponding information
If ($ name = "neo ")
{
?>
<Font face = "Arial" size = "-1">
Welcome to the parent, Neo.
<P>
You may have been forced to do this by force, oh, an improper film! </Font>
<?
}
?>
<?
// If the password is incorrect
If ($ name! = "Neo ")
{
?>
<Font face = "Arial" size = "-1">
I want to know if you have heard of Shakespeare, <? Echo $ name;?>.
<P>
He asked to get a bunch of roses from another name, because it may smell more fragrant.
<P>
Unfortunately, I don't agree with you. Access Denied!
</Font>
<?
}
?>
</Center>
</Body>
</Html>
--------------------------------------------------------------------------------
In this case, the "if" statement returns two types of information by judging whether the entered password 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 ";
}
}
}
?>
In PHP, the simplest condition statement is the if statement, which is generally as follows :--------------------------------------------------------------------------------...