PHP4 Practical Application (3)

Source: Internet
Author: User
Tags php code
In PHP, the simplest form of a conditional statement is an "if" statement, which is generally as follows:
--------------------------------------------------------------------------------
if (condition)
{
Do this!
}
--------------------------------------------------------------------------------
The "condition" here is a description of the condition in which PHP is judged to derive any value of "true" or "false". If the value is true, all the PHP code in the braces will be executed, but if the code in the large bracket is false, it will be ignored to continue the row after the "if" statement structure block.


We show you how the "if" statement works by adding an example of authentication to the "login.php" script above. Access is allowed only if the user entered a username that 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 force to force you to do it,,, Oh, improper film! </FONT>

<?
}
?>


<?
If the code is wrong,
if ($name!= "Neo")
{
?>


< font face= "Arial" size= "-1" >
I wonder if you've ever heard of Shakespeare , <? Echo $name;
< p>
He asked for a rose of another name, because the bouquet might smell more aromatic.
< p>
For you, unfortunately, I disagree. Refused to enter!
</FONT>

<?
}
?>


</center>
</body>

--------------------------------------------------------------------------------
In this case, the "if" statement feeds the two types of information by determining 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";
}
}
}

?>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.