PHP
  Home arrow PHP arrow Page 5 - PHP 101 (Part 2) - Shakespeare's Rose
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

PHP 101 (Part 2) - Shakespeare's Rose
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 10
    2000-08-08

    Table of Contents:
  • PHP 101 (Part 2) - Shakespeare's Rose
  • Form...
  • ...And Function
  • Operating With Extreme Caution
  • Shakespeare In The Matrix
  • If Not This, Then What?
  • Fortune Smiles
  • Submitting To The King
  • Miscellaneous Notes

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    PHP 101 (Part 2) - Shakespeare's Rose - Shakespeare In The Matrix


    (Page 5 of 9 )

    In PHP, the simplest form of conditional statement is the "if" statement, which looks something like this:

    if (condition) { do this! }
    The "condition" here is a conditional expression, which evaluates to either true or false. If the statement evaluates to true, all PHP code within the curly braces is executed; if not, the code within the curly braces is skipped and the lines following the "if" construct are executed.

    Let's show you how the "if" statement works by adding a little user authentication to the "login.php4" script above, such that access will be granted only when the user enters the name "neo".


    <html> <head> <basefont face="Arial"> </head> <body> <center> <? // check name and print appropriate message if ($name == "neo") { ?> <font face="Arial" size="-1"> Welcome to the Matrix, Neo. <p> May The Force be with you...oops, wrong movie! </font> <? } ?> <? // if password is wrong if ($name != "neo") { ?> <font face="Arial" size="-1"> I wonder if you've heard of Shakespeare, <? echo $name; ?>. <p> He postulated that a rose by any other name would smell just as sweet. <p> Unfortunately for you, I disagree. Access denied. </font> <? } ?> </center> </body> </html>
    In this case, the two "if" statements present an appropriate message, depending on whether or not the right password was entered. Of course, PHP also lets you "nest" conditional statements - for example, this is perfectly valid PHP code:

    <? if ($day == "Thursday") { if ($time == "12") { if ($place == "Italy") { $lunch = "pasta"; } } } ?>

    More PHP Articles
    More By Vikram Vaswani and Harish Kamath, (c) Melonfire


     

       

    PHP ARTICLES

    - Validating Web Forms with the Code Igniter P...
    - Output Buffering
    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway