Author: Sun Movement
In PHP, the simplest form of conditional statement is the "if" statement, which generally looks like the following:
--------------- -------------------------------------------------- ---------------
if (condition)
{
do this!
}
---------- -------------------------------------------------- ------------------
The "condition" here is a description of a condition. PHP will get either "true" or "false" after judgment. value. If it is true, all the PHP code in the curly brackets will be executed. On the contrary, if it is false, the code in the curly brackets will be ignored and execution will continue with the lines after the "if" statement structure block.
We will show you how the "if" statement works by adding an authentication example to the "login.php" script above. Access is only allowed if the username entered by the user 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 matrix, Neo.
< p>
Maybe you were forced to do this by force,,,oh, illicit video! < /font>
< ?
}
?>
< ?
//If the password is wrong
if ($name != "neo")
{
?>
< font face="Arial" size="-1">
I want to know Have you ever heard of Shakespeare, < ? echo $name; ?>.
< p>
He asked for a bouquet of roses by another name because that bouquet might smell more fragrant Some.
< p>
Unfortunately for you, I disagree. Entry refused!
< /font>
< ?
}
?>
< /center>
< /body>
< /html>
---------------------------------------- ---------------------------------------------
In this case Below, the "if" statement feeds back the corresponding two pieces of information by judging whether the entered password is correct. PHP also allows you to "nest" conditional statements - for example, this is a valid piece of PHP code:
--------------------- -------------------------------------------------- -------
< ?
if ($day == "Thursday")
{
if ($time == "12")
{
if ($place == "Italy")
{
$lunch = "pasta";
}
}
}
?>