SlideShare a Scribd company logo
PHP & MySQL Christos Efstratiou
Architecture Web Browser Web Server Request Page Page with  PHP code Read File PHP  Interpreter Pass PHP page and server variables (GET attributes, Server settings, etc.) Generate  HTML page Send  HTML page MySQL Interact with Database
PHP Syntax ,[object Object],[object Object],[object Object],[object Object],<?  $name  =   “World” ;   ?> <html> <body> <h1>Hello,  <?  echo  $name ;  ?>  </h1> </body> </html> <? include ( “header.html” ); if ( strpos ( $_SERVER[ “HTTP_USER_AGENT” ] ,  “MSIE” ) !==  FALSE ) { echo “You are using Internet explorer!”; } include ( “footer.html” ); ?>
PHP Syntax - Variables ,[object Object],$foo  =   &quot;0&quot; ;       // $foo is string (ASCII 48) $foo  +=  2 ;       // $foo is now an integer (2) $foo  =  $foo  +  1.3 ;      // $foo is now a float (3.3) ,[object Object],$foo  =   1 0 ;       // $foo is  an integer $ bar   =   (boolean)  $foo ;     //  $bar is boolean (true) ,[object Object],$ x   =  0 ;       $ y   =   false ; if (  $ x   ==   $ y  )  //  this is true   ,[object Object],$ x   =  0 ;       $ y   =   false ; if (  $ x   = = =   $ y  )  //  this is not true, different types
PHP Syntax - Strings ,[object Object],[object Object],$ str   =   ‘This is an  example’ ;       //   is not expanded to new line ,[object Object],$ val   =   5 ;   $ str   =   “The value is:  $var  ” ;     //  The string is: “The value is: 5” with a new line at the end       ,[object Object],$ val   =   5 ;   $ str   =   ‘The ’  .  ‘value is: ’  .   $var  .  “” ;   ,[object Object],$ str{2}  =   ‘T’   ;     //  The third character of string
PHP Syntax - Arrays ,[object Object],[object Object],$arr[1]  =  ‘Test’   ;     // Using integers as keys $arr [ ‘first’ ] =  ‘Test’   ;   // Using strings as keys $arr  =   array( &quot;foo&quot;   =>   &quot;bar&quot; ,   12   =>   true );   $arr[5]   =   10 ; // The array is now: (“foo”=> “bar”, 12=>true, 5=>10) ,[object Object],[object Object],$arr  =   array(  “first&quot;   =>    array( &quot;bar&quot; ,    ‘Test’   ),    “ second&quot;   =>    array( 1   =>   true ,    2   =>   false )  )   ;
PHP Syntax - Control Structures ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],$foo  =  array(   “Nigel”   =>   “nigel@comp.lancs.ac.uk”  ,     “ Chris”   =>   “efstrati@comp.lancs.ac.uk”   ,   “ Rob”   =>   “r.hooper@lancaster.ac.uk”   ,   “ Oliver”   =>   “stortz@comp.lancs.ac.uk”   ); foreach ( $foo  as  $name => $email ) { echo   “<p>Name:  $name  <br/>”   ; echo   “Email:  $email  </p>”   ; }
PHP Syntax - Functions ,[object Object],<?  function  foo ( $arg_1 ,  $arg_2 ,  /* ..., */  $arg_n ) {     echo  &quot;Example function.&quot; ;     return  $retval ; } ?>   ,[object Object],<?   $ g val  = 5 ;     // Global variable function  foo () {   global  $ g val  ;     // The function has now access to the global var (by reference)      echo  “ Gval:  $ g val   .&quot; ; } ?>
Pointers & pass by reference ,[object Object],[object Object],$foo  =  'Bob' ;               // Assign the value 'Bob' to $foo $bar  = & $foo ;               // Reference $foo via $bar. $bar  =  &quot;My name is $bar&quot; ;   // Alter $bar... echo  $foo ;                  // $foo is altered too. ,[object Object],function & add_some_extra (& $string ) { $string   .=  “ some more &quot; ;  return  $string ; } $foo   =&   add_some_extra ( $str );
Classes ,[object Object],class  Cart  {     var  $items ;   // Items in our shopping cart     // Add $num articles of $artnr to the cart       function  add_item ( $artnr ,  $num ) {          $this -> items [ $artnr ] +=  $num ;     } } $ myC art  = new  Cart ;    $ myCart -> myVar  =   “ test &quot; ;     //  This object has a new attribute not defined by the class ,[object Object],class  Named_Cart  extends  Cart  { ………     }
Serialization ,[object Object],   include( &quot;classa.inc&quot; );       $a  = new  A ;    $s  =  serialize ( $a );    // store $s somewhere    $fp  =  fopen ( &quot;store&quot; ,  &quot;w&quot; );    fwrite ( $fp ,  $s );    fclose ( $fp );   include( &quot;classa.inc&quot; );    $s  =  implode ( &quot;&quot; ,  file ( &quot;store&quot; ));    $a  =  unserialize ( $s );    // now use the object.      $a -> show_one ();
OO support in Version 5 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Programming techniques Separate code from GUI ,[object Object],[object Object],[object Object]
Programming techniques Template example <html> <head><title> {PAGETITLE} </title></head> <body> <table> <tr><td colspan=“2”> <h1> {PAGETITLE} </h1></td></tr> <tr> <td> {OUT} </td> <td>Content</td> </tr> </table> </body> </html> include(“template.inc”) $tpl = new Template(“mytemplates/”); // Create template object $tpl->set_file(“MainPage”, “mainPage.html”); // Load the template file $tpl->set_var(“PAGETITLE”, “My Page”); // Assign values to variables $tpl->set_var(“OUT”, “Test content”); $tpl->parse(“Output”, “MainPage”); // Parse page into variable Output $tpl->p(“Output”); // Print the Output var mainPage.html index.php
Programming techniques Template example <html> <head><title> My Page </title></head> <body> <table> <tr><td colspan=“2”> <h1> My Page </h1></td></tr> <tr> <td> Test content </td> <td>Content</td> </tr> </table> </body> </html> include(“template.inc”) $tpl = new Template(“mytemplates/”); // Create template object $tpl->set_file(“MainPage”, “mainPage.html”); // Load the template file $tpl->set_var(“PAGETITLE”, “My Page”); // Assign values to variables $tpl->set_var(“OUT”, “Test content”); $tpl->parse(“Output”, “MainPage”); // Parse page into variable Output $tpl->p(“Output”); // Print the Output var mainPage.html index.php
Programming techniques Template example 2 <html> <head><title> {PAGETITLE} </title></head> <body> <table> <tr><td colspan=“2”> <h1> {PAGETITLE} </h1></td></tr> <tr> <td> {OUT} </td> <td>Content</td> </tr> </table> </body> </html> <!– start box --> <table> <tr> <td colspan=“2”><b> {TITLE} </b></td> </tr> <!– BEGIN row --> <tr> <td> {NUM} </td> <td> {BIGNUM} </td> </tr> <!– END row --> </table> <!– end box --> include(&quot;./template.inc&quot;);  $t = new Template(&quot;/page/to/webserver/template&quot;, &quot;keep&quot;); //  define variables named page and box, referencing files   $t->set_file(array( &quot;page&quot; => &quot;page.ihtml&quot;, &quot;box&quot; => &quot;box.ihtml&quot;)); // define variable TITLE and PAGETITLE   $t->set_var(array(&quot;TITLE&quot; => &quot;Testpage&quot;, &quot;PAGETITLE&quot; => “ test &quot;));  # extract the block &quot;row&quot; from &quot;box&quot;, creat e  a  reference to {rows}&quot;.   $t->set_block(&quot;box&quot;, &quot;row&quot;, &quot;rows&quot;);  # define NUM and BIGNUM, then append &quot;row&quot; to &quot;rows&quot;...  for ($i=1; $i<=3; $i++)  {  $n = $i; $nn = $i*10;  $t->set_var(array(&quot;NUM&quot; => $n, &quot;BIGNUM&quot; => $nn));  $t->parse(&quot;rows&quot;, &quot;row&quot;, true);  } # build out from box, then build out put  from page...  $t->parse(&quot;OUT&quot;, &quot;box“ ); $t->parse(“Output” , &quot;page&quot;));  # finish out and print it.  $t->p(&quot;OUT&quot;); ?>
Programming techniques Template example 2 <html> <head><title> test </title></head> <body> <table> <tr><td colspan=“2”> <h1> test </h1></td></tr> <tr> <td> {OUT} </td> <td>Content</td> </tr> </table> </body> </html> <!– start box --> <table> <tr> <td colspan=“2”><b> Testpage </b></td> </tr> <!– BEGIN row --> <tr> <td> {NUM} </td> <td> {BIGNUM} </td> </tr> <!– END row --> </table> <!– end box --> include(&quot;./template.inc&quot;);  $t = new Template(&quot;/page/to/webserver/template&quot;, &quot;keep&quot;); //  define variables named page and box, referencing files   $t->set_file(array( &quot;page&quot; => &quot;page.ihtml&quot;, &quot;box&quot; => &quot;box.ihtml&quot;)); // define variable TITLE and PAGETITLE   $t->set_var(array(&quot;TITLE&quot; => &quot;Testpage&quot;, &quot;PAGETITLE&quot; => “ test &quot;));  # extract the block &quot;row&quot; from &quot;box&quot;, creat e  a  reference to {rows}&quot;.   $t->set_block(&quot;box&quot;, &quot;row&quot;, &quot;rows&quot;);  # define NUM and BIGNUM, then append &quot;row&quot; to &quot;rows&quot;...  for ($i=1; $i<=3; $i++)  {  $n = $i; $nn = $i*10;  $t->set_var(array(&quot;NUM&quot; => $n, &quot;BIGNUM&quot; => $nn));  $t->parse(&quot;rows&quot;, &quot;row&quot;, true);  } # build out from box, then build out put  from page...  $t->parse(&quot;OUT&quot;, &quot;box“ ); $t->parse(“Output” , &quot;page&quot;));  # finish out and print it.  $t->p(&quot;OUT&quot;); ?>
Programming techniques Template example 2 <html> <head><title> test </title></head> <body> <table> <tr><td colspan=“2”> <h1> test </h1></td></tr> <tr> <td> {OUT} </td> <td>Content</td> </tr> </table> </body> </html> <!– start box --> <table> <tr> <td colspan=“2”><b> Testpage </b></td> </tr> {rows} </table> <!– end box --> include(&quot;./template.inc&quot;);  $t = new Template(&quot;/page/to/webserver/template&quot;, &quot;keep&quot;); //  define variables named page and box, referencing files   $t->set_file(array( &quot;page&quot; => &quot;page.ihtml&quot;, &quot;box&quot; => &quot;box.ihtml&quot;)); // define variable TITLE and PAGETITLE   $t->set_var(array(&quot;TITLE&quot; => &quot;Testpage&quot;, &quot;PAGETITLE&quot; => “ test &quot;));  # extract the block &quot;row&quot; from &quot;box&quot;, creat e  a  reference to {rows}&quot;.   $t->set_block(&quot;box&quot;, &quot;row&quot;, &quot;rows&quot;);  # define NUM and BIGNUM, then append &quot;row&quot; to &quot;rows&quot;...  for ($i=1; $i<=3; $i++)  {  $n = $i; $nn = $i*10;  $t->set_var(array(&quot;NUM&quot; => $n, &quot;BIGNUM&quot; => $nn));  $t->parse(&quot;rows&quot;, &quot;row&quot;, true);  } # build out from box, then build out put  from page...  $t->parse(&quot;OUT&quot;, &quot;box“ ); $t->parse(“Output” , &quot;page&quot;));  # finish out and print it.  $t->p(&quot;OUT&quot;); ?> <!– Box row --> <tr> <td> {NUM} </td> <td> {BIGNUM} </td> </tr>
Programming techniques Template example 2 <html> <head><title> test </title></head> <body> <table> <tr><td colspan=“2”> <h1> test </h1></td></tr> <tr> <td> {OUT} </td> <td>Content</td> </tr> </table> </body> </html> <!– start box --> <table> <tr> <td colspan=“2”><b> Testpage </b></td> </tr> {rows} </table> <!– end box --> include(&quot;./template.inc&quot;);  $t = new Template(&quot;/page/to/webserver/template&quot;, &quot;keep&quot;); //  define variables named page and box, referencing files   $t->set_file(array( &quot;page&quot; => &quot;page.ihtml&quot;, &quot;box&quot; => &quot;box.ihtml&quot;)); // define variable TITLE and PAGETITLE   $t->set_var(array(&quot;TITLE&quot; => &quot;Testpage&quot;, &quot;PAGETITLE&quot; => “ test &quot;));  # extract the block &quot;row&quot; from &quot;box&quot;, creat e  a  reference to {rows}&quot;.   $t->set_block(&quot;box&quot;, &quot;row&quot;, &quot;rows&quot;);  # define NUM and BIGNUM, then append &quot;row&quot; to &quot;rows&quot;...  for ($i=1; $i<=3; $i++)  {  $n = $i; $nn = $i*10;  $t->set_var(array(&quot;NUM&quot; => $n, &quot;BIGNUM&quot; => $nn));  $t->parse(&quot;rows&quot;, &quot;row&quot;, true);  } # build out from box, then build out put  from page...  $t->parse(&quot;OUT&quot;, &quot;box“ ); $t->parse(“Output” , &quot;page&quot;));  # finish out and print it.  $t->p(&quot;OUT&quot;); ?> <tr> <td> 1 </td> <td> 10 </td> </tr>
Programming techniques Template example 2 <html> <head><title> test </title></head> <body> <table> <tr><td colspan=“2”> <h1> test </h1></td></tr> <tr> <td> {OUT} </td> <td>Content</td> </tr> </table> </body> </html> <!– start box --> <table> <tr> <td colspan=“2”><b> Testpage </b></td> </tr> {rows} </table> <!– end box --> include(&quot;./template.inc&quot;);  $t = new Template(&quot;/page/to/webserver/template&quot;, &quot;keep&quot;); //  define variables named page and box, referencing files   $t->set_file(array( &quot;page&quot; => &quot;page.ihtml&quot;, &quot;box&quot; => &quot;box.ihtml&quot;)); // define variable TITLE and PAGETITLE   $t->set_var(array(&quot;TITLE&quot; => &quot;Testpage&quot;, &quot;PAGETITLE&quot; => “ test &quot;));  # extract the block &quot;row&quot; from &quot;box&quot;, creat e  a  reference to {rows}&quot;.   $t->set_block(&quot;box&quot;, &quot;row&quot;, &quot;rows&quot;);  # define NUM and BIGNUM, then append &quot;row&quot; to &quot;rows&quot;...  for ($i=1; $i<=3; $i++)  {  $n = $i; $nn = $i*10;  $t->set_var(array(&quot;NUM&quot; => $n, &quot;BIGNUM&quot; => $nn));  $t->parse(&quot;rows&quot;, &quot;row&quot;, true);  } # build out from box, then build out put  from page...  $t->parse(&quot;OUT&quot;, &quot;box“ ); $t->parse(“Output” , &quot;page&quot;));  # finish out and print it.  $t->p(&quot;OUT&quot;); ?> <tr> <td> 1 </td> <td> 10 </td> </tr> <tr> <td> 2 </td> <td> 20 </td> </tr>
Programming techniques Template example 2 <html> <head><title> test </title></head> <body> <table> <tr><td colspan=“2”> <h1> test </h1></td></tr> <tr> <td> {OUT} </td> <td>Content</td> </tr> </table> </body> </html> <!– start box --> <table> <tr> <td colspan=“2”><b> Testpage </b></td> </tr> <tr> <td> 1 </td> <td> 10 </td> </tr> <tr> <td> 2 </td> <td> 20 </td> </tr> </table> <!– end box --> include(&quot;./template.inc&quot;);  $t = new Template(&quot;/page/to/webserver/template&quot;, &quot;keep&quot;); //  define variables named page and box, referencing files   $t->set_file(array( &quot;page&quot; => &quot;page.ihtml&quot;, &quot;box&quot; => &quot;box.ihtml&quot;)); // define variable TITLE and PAGETITLE   $t->set_var(array(&quot;TITLE&quot; => &quot;Testpage&quot;, &quot;PAGETITLE&quot; => “ test &quot;));  # extract the block &quot;row&quot; from &quot;box&quot;, creat e  a  reference to {rows}&quot;.   $t->set_block(&quot;box&quot;, &quot;row&quot;, &quot;rows&quot;);  # define NUM and BIGNUM, then append &quot;row&quot; to &quot;rows&quot;...  for ($i=1; $i<=3; $i++)  {  $n = $i; $nn = $i*10;  $t->set_var(array(&quot;NUM&quot; => $n, &quot;BIGNUM&quot; => $nn));  $t->parse(&quot;rows&quot;, &quot;row&quot;, true);  } # build out from box, then build out put  from page...  $t->parse(&quot;OUT&quot;, &quot;box“ ); $t->parse(“Output” , &quot;page&quot;));  # finish out and print it.  $t->p(&quot;O utput &quot;); ?>
Programming techniques Template example 2 <html> <head><title> test </title></head> <body> <table> <tr><td colspan=“2”> <h1> test </h1></td></tr> <tr> <td> <table> <tr> <td colspan=“2”><b>Testpage</b></td> </tr> <tr> <td>1</td> <td>10</td> </tr> <tr> <td>2</td> <td>20</td> </tr> </table> </td> <td>Content</td> </tr> </table> </body> </html> include(&quot;./template.inc&quot;);  $t = new Template(&quot;/page/to/webserver/template&quot;, &quot;keep&quot;); //  define variables named page and box, referencing files   $t->set_file(array( &quot;page&quot; => &quot;page.ihtml&quot;, &quot;box&quot; => &quot;box.ihtml&quot;)); // define variable TITLE and PAGETITLE   $t->set_var(array(&quot;TITLE&quot; => &quot;Testpage&quot;, &quot;PAGETITLE&quot; => “ test &quot;));  # extract the block &quot;row&quot; from &quot;box&quot;, creat e  a  reference to {rows}&quot;.   $t->set_block(&quot;box&quot;, &quot;row&quot;, &quot;rows&quot;);  # define NUM and BIGNUM, then append &quot;row&quot; to &quot;rows&quot;...  for ($i=1; $i<=3; $i++)  {  $n = $i; $nn = $i*10;  $t->set_var(array(&quot;NUM&quot; => $n, &quot;BIGNUM&quot; => $nn));  $t->parse(&quot;rows&quot;, &quot;row&quot;, true);  } # build out from box, then build out put  from page...  $t->parse(&quot;OUT&quot;, &quot;box“ ); $t->parse(“Output” , &quot;page&quot;));  # finish out and print it.  $t->p(&quot;OUT&quot;); ?>
Programming techniques Template example 2 <html> <head><title> test </title></head> <body> <table> <tr><td colspan=“2”> <h1> test </h1></td></tr> <tr> <td> <table> <tr> <td colspan=“2”><b> Testpage </b></td> </tr> <tr> <td> 1 </td> <td> 10 </td> </tr> <tr> <td> 2 </td> <td> 20 </td> </tr> </table> </td> <td>Content</td> </tr> </table> </body> </html> Content test 30  3 20  2 10  1 Testpage
Interacting with the user ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],$_GET = array(“a”=>”alpha”, “b”=>”beta”);
Handling Forms
Handling Forms <form method=“ post ” action=“index.php”> <input type=“hidden” name=“ id ” value=“100” /> <table> <tr> <td>User</td> <td><input type=“text” name=“ user ” /></td> </tr> <tr> <td>Password</td> <td><input type=“password” name=“ passwd ” /> </td> </tr> <tr> <td colspan=“2”> <input type=“submit” name=“ Login ”  value=“Login” /> </td> </tr> </table> </form>
Handling Forms <form method=“ post ” action=“index.php”> <input type=“hidden” name=“ id ” value=“100” /> <table> <tr> <td>User</td> <td><input type=“text” name=“ user ” /></td> </tr> <tr> <td>Password</td> <td><input type=“password” name=“ passwd ” /> </td> </tr> <tr> <td colspan=“2”> <input type=“submit” name=“ Login ”  value=“Login” /> </td> </tr> </table> </form> $ok = false; if (array_key_exists(“submit”,  $_POST ) && ( $_POST [“submit”] == “Login”) ) { $ok = CheckLogin( $_POST [“id”], $_POST [“user”], $_POST [“passwd”]); } if ($ok) { include(“restrictedArea.html”); } else { include(“loginForm.html”); }
Handling Forms <form method=“ get ” action=“index.php”> <input type=“hidden” name=“ id ” value=“100” /> <table> <tr> <td>User</td> <td><input type=“text” name=“ user ” /></td> </tr> <tr> <td>Password</td> <td><input type=“password” name=“ passwd ” /> </td> </tr> <tr> <td colspan=“2”> <input type=“submit” name=“ Login ”  value=“Login” /> </td> </tr> </table> </form> $ok = false; if (array_key_exists(“submit”,  $_ GET ) && ( $_ GET [“submit”] == “Login”) ) { $ok = CheckLogin( $_GET [“id”], $_GET [“user”], $_GET [“passwd”]); } if ($ok) { include(“restrictedArea.html”); } else { include(“loginForm.html”); }
Handling Forms ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],$ret  =  ereg ( ‘^([a-z0-9_]|-|.)+@(([a-z0-9_]|-)+.)+[a-z]{2,4}$’ ,  $string );
Sessions ,[object Object],[object Object],[object Object]
Sessions ,[object Object],[object Object],[object Object]
Sessions <? // Login page session_start(); // Process the login form …………………… // Login is completed $_SESSION[‘user’] = $_POST[‘user’]; $_SESSION[‘passwd’] = $_POST[‘passwd’]; // Redirect to the private page header(&quot;Location:  ”. ” http:// www.server.com/nextpage.php” ); ?> <? // next page session_start(); // Check login user if (!array_key_exists(“user”, $_SESSION)) { // No user logged in echo “You need to login first”; exit(); } echo “Hello “. $_SESSION[“user”] .”!<br/>”; ?>
Sessions ,[object Object],[object Object],[object Object]
Authentication ,[object Object],[object Object],[object Object],[object Object]
MySQL ,[object Object],[object Object],[object Object],[object Object],[object Object]
MySQL management ,[object Object],[object Object],[object Object],[object Object]
MySQL Interaction ,[object Object],[object Object],[object Object],[object Object]
PHP Support for MySQL ,[object Object],$link = mysql_connect(“localhost”, “dbuser”, “dbpass”); If ($link == false) die(“Could not connect: “. mysql_error()); ,[object Object],$link = mysql_select_db(“myDatabase”, $link); If ($link == false) die(“Could not select database: “. mysql_error()); ,[object Object],$query = “INSERT INTO contacts (name, email) VALUES (‘Chris’, ‘efstrati@comp.lancs.ac.uk’)”; $res = mysql_query($query, $link); If ($res == false) echo “Could not perform insert: “. mysql_error(); else { $userID = mysql_insert_id($link); echo “New user id: $userID”; }
MySQL retrieving results $query = “SELECT * FROM contacts”; $res = mysql_query($query, $link); while ($record = mysql_fetch_assoc($res)) { echo “Name: “.$record[‘name’].”, email: “.$record[‘email’].”<br/>”; } mysql_free_results($res); ,[object Object],[object Object],[object Object]
MySQL & PHP:  Things to remember ,[object Object],[object Object]
Suggested reading ,[object Object],[object Object],[object Object]

More Related Content

What's hot

Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHP
Ahmed Swilam
 
PHP - Introduction to PHP
PHP -  Introduction to PHPPHP -  Introduction to PHP
PHP - Introduction to PHP
Vibrant Technologies & Computers
 
Php Calling Operators
Php Calling OperatorsPhp Calling Operators
Php Calling Operatorsmussawir20
 
Basic PHP
Basic PHPBasic PHP
Basic PHP
Todd Barber
 
Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP Strings
Ahmed Swilam
 
PHP Basic
PHP BasicPHP Basic
PHP Basic
Yoeung Vibol
 
Introduction to PHP Lecture 1
Introduction to PHP Lecture 1Introduction to PHP Lecture 1
Introduction to PHP Lecture 1
Ajay Khatri
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
Muthuselvam RS
 
perl usage at database applications
perl usage at database applicationsperl usage at database applications
perl usage at database applicationsJoe Jiang
 
Introduction To Php For Wit2009
Introduction To Php For Wit2009Introduction To Php For Wit2009
Introduction To Php For Wit2009
cwarren
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQLOpen Source Package PHP & MySQL
Open Source Package PHP & MySQL
kalaisai
 
Making Sense of Twig
Making Sense of TwigMaking Sense of Twig
Making Sense of Twig
Brandon Kelly
 
Basics of Java Script (JS)
Basics of Java Script (JS)Basics of Java Script (JS)
Basics of Java Script (JS)
Ajay Khatri
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
Sopan Shewale
 
PHP Workshop Notes
PHP Workshop NotesPHP Workshop Notes
PHP Workshop Notes
Pamela Fox
 

What's hot (20)

Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHP
 
PHP - Introduction to PHP
PHP -  Introduction to PHPPHP -  Introduction to PHP
PHP - Introduction to PHP
 
Php Calling Operators
Php Calling OperatorsPhp Calling Operators
Php Calling Operators
 
Basic PHP
Basic PHPBasic PHP
Basic PHP
 
Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP Strings
 
PHP Basic
PHP BasicPHP Basic
PHP Basic
 
Introduction to PHP Lecture 1
Introduction to PHP Lecture 1Introduction to PHP Lecture 1
Introduction to PHP Lecture 1
 
Further Php
Further PhpFurther Php
Further Php
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
 
perl usage at database applications
perl usage at database applicationsperl usage at database applications
perl usage at database applications
 
Introduction To Php For Wit2009
Introduction To Php For Wit2009Introduction To Php For Wit2009
Introduction To Php For Wit2009
 
slidesharenew1
slidesharenew1slidesharenew1
slidesharenew1
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQLOpen Source Package PHP & MySQL
Open Source Package PHP & MySQL
 
Variables in PHP
Variables in PHPVariables in PHP
Variables in PHP
 
Php Rss
Php RssPhp Rss
Php Rss
 
Making Sense of Twig
Making Sense of TwigMaking Sense of Twig
Making Sense of Twig
 
Basics of Java Script (JS)
Basics of Java Script (JS)Basics of Java Script (JS)
Basics of Java Script (JS)
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 
PHP Workshop Notes
PHP Workshop NotesPHP Workshop Notes
PHP Workshop Notes
 

Viewers also liked

Electronic Information Committee and Web Master Report
Electronic Information Committee and Web Master ReportElectronic Information Committee and Web Master Report
Electronic Information Committee and Web Master Reportwebhostingguy
 
Plesk 8.1 for Linux/UNIX
Plesk 8.1 for Linux/UNIXPlesk 8.1 for Linux/UNIX
Plesk 8.1 for Linux/UNIXwebhostingguy
 
Server Virtualization and Cloud Computing: Four Hidden Impacts on ...
Server Virtualization and Cloud Computing: Four Hidden Impacts on ...Server Virtualization and Cloud Computing: Four Hidden Impacts on ...
Server Virtualization and Cloud Computing: Four Hidden Impacts on ...webhostingguy
 
A Reseller's Guide to Using Helm
A Reseller's Guide to Using HelmA Reseller's Guide to Using Helm
A Reseller's Guide to Using Helmwebhostingguy
 
ESX Server 3i Installable Setup Guide
ESX Server 3i Installable Setup GuideESX Server 3i Installable Setup Guide
ESX Server 3i Installable Setup Guidewebhostingguy
 
Koruyucu Aileliğin Yaygınlaşması İçin Bir Model Önerisi: Koruyucu Aile Tanıtı...
Koruyucu Aileliğin Yaygınlaşması İçin Bir Model Önerisi: Koruyucu Aile Tanıtı...Koruyucu Aileliğin Yaygınlaşması İçin Bir Model Önerisi: Koruyucu Aile Tanıtı...
Koruyucu Aileliğin Yaygınlaşması İçin Bir Model Önerisi: Koruyucu Aile Tanıtı...
İsmail Küçüksarı
 
Peter h. oppenheimer the sudetendeutsche landsmannschaft - journal of histo...
Peter h. oppenheimer   the sudetendeutsche landsmannschaft - journal of histo...Peter h. oppenheimer   the sudetendeutsche landsmannschaft - journal of histo...
Peter h. oppenheimer the sudetendeutsche landsmannschaft - journal of histo...RareBooksnRecords
 
Artibel belgelendi̇rme
Artibel belgelendi̇rmeArtibel belgelendi̇rme
Artibel belgelendi̇rme
Fatih Yigit
 
Activities of Dr. Sherazi
Activities of Dr. SheraziActivities of Dr. Sherazi
Activities of Dr. SheraziTufail Sherazi
 
Tonlakazan
TonlakazanTonlakazan
Tonlakazan
Mobildev
 
Présentation de Tsung chez Leboncoin
Présentation de Tsung chez LeboncoinPrésentation de Tsung chez Leboncoin
Présentation de Tsung chez LeboncoinRodolphe Quiédeville
 
Php sitesi
Php sitesiPhp sitesi
Php sitesisersld89
 

Viewers also liked (16)

Electronic Information Committee and Web Master Report
Electronic Information Committee and Web Master ReportElectronic Information Committee and Web Master Report
Electronic Information Committee and Web Master Report
 
ppt_rs.jpg
ppt_rs.jpgppt_rs.jpg
ppt_rs.jpg
 
Plesk 8.1 for Linux/UNIX
Plesk 8.1 for Linux/UNIXPlesk 8.1 for Linux/UNIX
Plesk 8.1 for Linux/UNIX
 
(Powerpoint slides)
(Powerpoint slides)(Powerpoint slides)
(Powerpoint slides)
 
Server Virtualization and Cloud Computing: Four Hidden Impacts on ...
Server Virtualization and Cloud Computing: Four Hidden Impacts on ...Server Virtualization and Cloud Computing: Four Hidden Impacts on ...
Server Virtualization and Cloud Computing: Four Hidden Impacts on ...
 
mysqlHiep.ppt
mysqlHiep.pptmysqlHiep.ppt
mysqlHiep.ppt
 
Download It
Download ItDownload It
Download It
 
A Reseller's Guide to Using Helm
A Reseller's Guide to Using HelmA Reseller's Guide to Using Helm
A Reseller's Guide to Using Helm
 
ESX Server 3i Installable Setup Guide
ESX Server 3i Installable Setup GuideESX Server 3i Installable Setup Guide
ESX Server 3i Installable Setup Guide
 
Koruyucu Aileliğin Yaygınlaşması İçin Bir Model Önerisi: Koruyucu Aile Tanıtı...
Koruyucu Aileliğin Yaygınlaşması İçin Bir Model Önerisi: Koruyucu Aile Tanıtı...Koruyucu Aileliğin Yaygınlaşması İçin Bir Model Önerisi: Koruyucu Aile Tanıtı...
Koruyucu Aileliğin Yaygınlaşması İçin Bir Model Önerisi: Koruyucu Aile Tanıtı...
 
Peter h. oppenheimer the sudetendeutsche landsmannschaft - journal of histo...
Peter h. oppenheimer   the sudetendeutsche landsmannschaft - journal of histo...Peter h. oppenheimer   the sudetendeutsche landsmannschaft - journal of histo...
Peter h. oppenheimer the sudetendeutsche landsmannschaft - journal of histo...
 
Artibel belgelendi̇rme
Artibel belgelendi̇rmeArtibel belgelendi̇rme
Artibel belgelendi̇rme
 
Activities of Dr. Sherazi
Activities of Dr. SheraziActivities of Dr. Sherazi
Activities of Dr. Sherazi
 
Tonlakazan
TonlakazanTonlakazan
Tonlakazan
 
Présentation de Tsung chez Leboncoin
Présentation de Tsung chez LeboncoinPrésentation de Tsung chez Leboncoin
Présentation de Tsung chez Leboncoin
 
Php sitesi
Php sitesiPhp sitesi
Php sitesi
 

Similar to PHP

Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9isadorta
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpointwebhostingguy
 
JQuery Presentation
JQuery PresentationJQuery Presentation
JQuery Presentation
Sony Jain
 
What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3
Jeremy Coates
 
Introduction to Modern Perl
Introduction to Modern PerlIntroduction to Modern Perl
Introduction to Modern Perl
Dave Cross
 
Introduction To Lamp
Introduction To LampIntroduction To Lamp
Introduction To Lamp
Amzad Hossain
 
Система рендеринга в Magento
Система рендеринга в MagentoСистема рендеринга в Magento
Система рендеринга в MagentoMagecom Ukraine
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Coursemussawir20
 
2014 database - course 2 - php
2014 database - course 2 - php2014 database - course 2 - php
2014 database - course 2 - phpHung-yu Lin
 
Bioinformatica 10-11-2011-p6-bioperl
Bioinformatica 10-11-2011-p6-bioperlBioinformatica 10-11-2011-p6-bioperl
Bioinformatica 10-11-2011-p6-bioperl
Prof. Wim Van Criekinge
 
Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5
Stephan Schmidt
 

Similar to PHP (20)

Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9
 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
 
Php
PhpPhp
Php
 
JQuery Presentation
JQuery PresentationJQuery Presentation
JQuery Presentation
 
What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3
 
Introduction to Modern Perl
Introduction to Modern PerlIntroduction to Modern Perl
Introduction to Modern Perl
 
Introduction To Lamp
Introduction To LampIntroduction To Lamp
Introduction To Lamp
 
Система рендеринга в Magento
Система рендеринга в MagentoСистема рендеринга в Magento
Система рендеринга в Magento
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Course
 
2014 database - course 2 - php
2014 database - course 2 - php2014 database - course 2 - php
2014 database - course 2 - php
 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
 
Bioinformatica 10-11-2011-p6-bioperl
Bioinformatica 10-11-2011-p6-bioperlBioinformatica 10-11-2011-p6-bioperl
Bioinformatica 10-11-2011-p6-bioperl
 
Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
 
Web development
Web developmentWeb development
Web development
 
Framework
FrameworkFramework
Framework
 
Php1
Php1Php1
Php1
 
Php Basic
Php BasicPhp Basic
Php Basic
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5
 

More from webhostingguy

Running and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test FrameworkRunning and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test Frameworkwebhostingguy
 
MySQL and memcached Guide
MySQL and memcached GuideMySQL and memcached Guide
MySQL and memcached Guidewebhostingguy
 
Novell® iChain® 2.3
Novell® iChain® 2.3Novell® iChain® 2.3
Novell® iChain® 2.3webhostingguy
 
Load-balancing web servers Load-balancing web servers
Load-balancing web servers Load-balancing web serversLoad-balancing web servers Load-balancing web servers
Load-balancing web servers Load-balancing web serverswebhostingguy
 
SQL Server 2008 Consolidation
SQL Server 2008 ConsolidationSQL Server 2008 Consolidation
SQL Server 2008 Consolidationwebhostingguy
 
Master Service Agreement
Master Service AgreementMaster Service Agreement
Master Service Agreementwebhostingguy
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...webhostingguy
 
Dell Reference Architecture Guide Deploying Microsoft® SQL ...
Dell Reference Architecture Guide Deploying Microsoft® SQL ...Dell Reference Architecture Guide Deploying Microsoft® SQL ...
Dell Reference Architecture Guide Deploying Microsoft® SQL ...webhostingguy
 
Managing Diverse IT Infrastructure
Managing Diverse IT InfrastructureManaging Diverse IT Infrastructure
Managing Diverse IT Infrastructurewebhostingguy
 
Web design for business.ppt
Web design for business.pptWeb design for business.ppt
Web design for business.pptwebhostingguy
 
IT Power Management Strategy
IT Power Management Strategy IT Power Management Strategy
IT Power Management Strategy webhostingguy
 
Excel and SQL Quick Tricks for Merchandisers
Excel and SQL Quick Tricks for MerchandisersExcel and SQL Quick Tricks for Merchandisers
Excel and SQL Quick Tricks for Merchandiserswebhostingguy
 
Parallels Hosting Products
Parallels Hosting ProductsParallels Hosting Products
Parallels Hosting Productswebhostingguy
 
Microsoft PowerPoint presentation 2.175 Mb
Microsoft PowerPoint presentation 2.175 MbMicrosoft PowerPoint presentation 2.175 Mb
Microsoft PowerPoint presentation 2.175 Mbwebhostingguy
 

More from webhostingguy (20)

File Upload
File UploadFile Upload
File Upload
 
Running and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test FrameworkRunning and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test Framework
 
MySQL and memcached Guide
MySQL and memcached GuideMySQL and memcached Guide
MySQL and memcached Guide
 
Novell® iChain® 2.3
Novell® iChain® 2.3Novell® iChain® 2.3
Novell® iChain® 2.3
 
Load-balancing web servers Load-balancing web servers
Load-balancing web servers Load-balancing web serversLoad-balancing web servers Load-balancing web servers
Load-balancing web servers Load-balancing web servers
 
SQL Server 2008 Consolidation
SQL Server 2008 ConsolidationSQL Server 2008 Consolidation
SQL Server 2008 Consolidation
 
What is mod_perl?
What is mod_perl?What is mod_perl?
What is mod_perl?
 
What is mod_perl?
What is mod_perl?What is mod_perl?
What is mod_perl?
 
Master Service Agreement
Master Service AgreementMaster Service Agreement
Master Service Agreement
 
Notes8
Notes8Notes8
Notes8
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
 
Dell Reference Architecture Guide Deploying Microsoft® SQL ...
Dell Reference Architecture Guide Deploying Microsoft® SQL ...Dell Reference Architecture Guide Deploying Microsoft® SQL ...
Dell Reference Architecture Guide Deploying Microsoft® SQL ...
 
Managing Diverse IT Infrastructure
Managing Diverse IT InfrastructureManaging Diverse IT Infrastructure
Managing Diverse IT Infrastructure
 
Web design for business.ppt
Web design for business.pptWeb design for business.ppt
Web design for business.ppt
 
IT Power Management Strategy
IT Power Management Strategy IT Power Management Strategy
IT Power Management Strategy
 
Excel and SQL Quick Tricks for Merchandisers
Excel and SQL Quick Tricks for MerchandisersExcel and SQL Quick Tricks for Merchandisers
Excel and SQL Quick Tricks for Merchandisers
 
OLUG_xen.ppt
OLUG_xen.pptOLUG_xen.ppt
OLUG_xen.ppt
 
Parallels Hosting Products
Parallels Hosting ProductsParallels Hosting Products
Parallels Hosting Products
 
Microsoft PowerPoint presentation 2.175 Mb
Microsoft PowerPoint presentation 2.175 MbMicrosoft PowerPoint presentation 2.175 Mb
Microsoft PowerPoint presentation 2.175 Mb
 
Reseller's Guide
Reseller's GuideReseller's Guide
Reseller's Guide
 

PHP

  • 1. PHP & MySQL Christos Efstratiou
  • 2. Architecture Web Browser Web Server Request Page Page with PHP code Read File PHP Interpreter Pass PHP page and server variables (GET attributes, Server settings, etc.) Generate HTML page Send HTML page MySQL Interact with Database
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14. Programming techniques Template example <html> <head><title> {PAGETITLE} </title></head> <body> <table> <tr><td colspan=“2”> <h1> {PAGETITLE} </h1></td></tr> <tr> <td> {OUT} </td> <td>Content</td> </tr> </table> </body> </html> include(“template.inc”) $tpl = new Template(“mytemplates/”); // Create template object $tpl->set_file(“MainPage”, “mainPage.html”); // Load the template file $tpl->set_var(“PAGETITLE”, “My Page”); // Assign values to variables $tpl->set_var(“OUT”, “Test content”); $tpl->parse(“Output”, “MainPage”); // Parse page into variable Output $tpl->p(“Output”); // Print the Output var mainPage.html index.php
  • 15. Programming techniques Template example <html> <head><title> My Page </title></head> <body> <table> <tr><td colspan=“2”> <h1> My Page </h1></td></tr> <tr> <td> Test content </td> <td>Content</td> </tr> </table> </body> </html> include(“template.inc”) $tpl = new Template(“mytemplates/”); // Create template object $tpl->set_file(“MainPage”, “mainPage.html”); // Load the template file $tpl->set_var(“PAGETITLE”, “My Page”); // Assign values to variables $tpl->set_var(“OUT”, “Test content”); $tpl->parse(“Output”, “MainPage”); // Parse page into variable Output $tpl->p(“Output”); // Print the Output var mainPage.html index.php
  • 16. Programming techniques Template example 2 <html> <head><title> {PAGETITLE} </title></head> <body> <table> <tr><td colspan=“2”> <h1> {PAGETITLE} </h1></td></tr> <tr> <td> {OUT} </td> <td>Content</td> </tr> </table> </body> </html> <!– start box --> <table> <tr> <td colspan=“2”><b> {TITLE} </b></td> </tr> <!– BEGIN row --> <tr> <td> {NUM} </td> <td> {BIGNUM} </td> </tr> <!– END row --> </table> <!– end box --> include(&quot;./template.inc&quot;); $t = new Template(&quot;/page/to/webserver/template&quot;, &quot;keep&quot;); // define variables named page and box, referencing files $t->set_file(array( &quot;page&quot; => &quot;page.ihtml&quot;, &quot;box&quot; => &quot;box.ihtml&quot;)); // define variable TITLE and PAGETITLE $t->set_var(array(&quot;TITLE&quot; => &quot;Testpage&quot;, &quot;PAGETITLE&quot; => “ test &quot;)); # extract the block &quot;row&quot; from &quot;box&quot;, creat e a reference to {rows}&quot;. $t->set_block(&quot;box&quot;, &quot;row&quot;, &quot;rows&quot;); # define NUM and BIGNUM, then append &quot;row&quot; to &quot;rows&quot;... for ($i=1; $i<=3; $i++) { $n = $i; $nn = $i*10; $t->set_var(array(&quot;NUM&quot; => $n, &quot;BIGNUM&quot; => $nn)); $t->parse(&quot;rows&quot;, &quot;row&quot;, true); } # build out from box, then build out put from page... $t->parse(&quot;OUT&quot;, &quot;box“ ); $t->parse(“Output” , &quot;page&quot;)); # finish out and print it. $t->p(&quot;OUT&quot;); ?>
  • 17. Programming techniques Template example 2 <html> <head><title> test </title></head> <body> <table> <tr><td colspan=“2”> <h1> test </h1></td></tr> <tr> <td> {OUT} </td> <td>Content</td> </tr> </table> </body> </html> <!– start box --> <table> <tr> <td colspan=“2”><b> Testpage </b></td> </tr> <!– BEGIN row --> <tr> <td> {NUM} </td> <td> {BIGNUM} </td> </tr> <!– END row --> </table> <!– end box --> include(&quot;./template.inc&quot;); $t = new Template(&quot;/page/to/webserver/template&quot;, &quot;keep&quot;); // define variables named page and box, referencing files $t->set_file(array( &quot;page&quot; => &quot;page.ihtml&quot;, &quot;box&quot; => &quot;box.ihtml&quot;)); // define variable TITLE and PAGETITLE $t->set_var(array(&quot;TITLE&quot; => &quot;Testpage&quot;, &quot;PAGETITLE&quot; => “ test &quot;)); # extract the block &quot;row&quot; from &quot;box&quot;, creat e a reference to {rows}&quot;. $t->set_block(&quot;box&quot;, &quot;row&quot;, &quot;rows&quot;); # define NUM and BIGNUM, then append &quot;row&quot; to &quot;rows&quot;... for ($i=1; $i<=3; $i++) { $n = $i; $nn = $i*10; $t->set_var(array(&quot;NUM&quot; => $n, &quot;BIGNUM&quot; => $nn)); $t->parse(&quot;rows&quot;, &quot;row&quot;, true); } # build out from box, then build out put from page... $t->parse(&quot;OUT&quot;, &quot;box“ ); $t->parse(“Output” , &quot;page&quot;)); # finish out and print it. $t->p(&quot;OUT&quot;); ?>
  • 18. Programming techniques Template example 2 <html> <head><title> test </title></head> <body> <table> <tr><td colspan=“2”> <h1> test </h1></td></tr> <tr> <td> {OUT} </td> <td>Content</td> </tr> </table> </body> </html> <!– start box --> <table> <tr> <td colspan=“2”><b> Testpage </b></td> </tr> {rows} </table> <!– end box --> include(&quot;./template.inc&quot;); $t = new Template(&quot;/page/to/webserver/template&quot;, &quot;keep&quot;); // define variables named page and box, referencing files $t->set_file(array( &quot;page&quot; => &quot;page.ihtml&quot;, &quot;box&quot; => &quot;box.ihtml&quot;)); // define variable TITLE and PAGETITLE $t->set_var(array(&quot;TITLE&quot; => &quot;Testpage&quot;, &quot;PAGETITLE&quot; => “ test &quot;)); # extract the block &quot;row&quot; from &quot;box&quot;, creat e a reference to {rows}&quot;. $t->set_block(&quot;box&quot;, &quot;row&quot;, &quot;rows&quot;); # define NUM and BIGNUM, then append &quot;row&quot; to &quot;rows&quot;... for ($i=1; $i<=3; $i++) { $n = $i; $nn = $i*10; $t->set_var(array(&quot;NUM&quot; => $n, &quot;BIGNUM&quot; => $nn)); $t->parse(&quot;rows&quot;, &quot;row&quot;, true); } # build out from box, then build out put from page... $t->parse(&quot;OUT&quot;, &quot;box“ ); $t->parse(“Output” , &quot;page&quot;)); # finish out and print it. $t->p(&quot;OUT&quot;); ?> <!– Box row --> <tr> <td> {NUM} </td> <td> {BIGNUM} </td> </tr>
  • 19. Programming techniques Template example 2 <html> <head><title> test </title></head> <body> <table> <tr><td colspan=“2”> <h1> test </h1></td></tr> <tr> <td> {OUT} </td> <td>Content</td> </tr> </table> </body> </html> <!– start box --> <table> <tr> <td colspan=“2”><b> Testpage </b></td> </tr> {rows} </table> <!– end box --> include(&quot;./template.inc&quot;); $t = new Template(&quot;/page/to/webserver/template&quot;, &quot;keep&quot;); // define variables named page and box, referencing files $t->set_file(array( &quot;page&quot; => &quot;page.ihtml&quot;, &quot;box&quot; => &quot;box.ihtml&quot;)); // define variable TITLE and PAGETITLE $t->set_var(array(&quot;TITLE&quot; => &quot;Testpage&quot;, &quot;PAGETITLE&quot; => “ test &quot;)); # extract the block &quot;row&quot; from &quot;box&quot;, creat e a reference to {rows}&quot;. $t->set_block(&quot;box&quot;, &quot;row&quot;, &quot;rows&quot;); # define NUM and BIGNUM, then append &quot;row&quot; to &quot;rows&quot;... for ($i=1; $i<=3; $i++) { $n = $i; $nn = $i*10; $t->set_var(array(&quot;NUM&quot; => $n, &quot;BIGNUM&quot; => $nn)); $t->parse(&quot;rows&quot;, &quot;row&quot;, true); } # build out from box, then build out put from page... $t->parse(&quot;OUT&quot;, &quot;box“ ); $t->parse(“Output” , &quot;page&quot;)); # finish out and print it. $t->p(&quot;OUT&quot;); ?> <tr> <td> 1 </td> <td> 10 </td> </tr>
  • 20. Programming techniques Template example 2 <html> <head><title> test </title></head> <body> <table> <tr><td colspan=“2”> <h1> test </h1></td></tr> <tr> <td> {OUT} </td> <td>Content</td> </tr> </table> </body> </html> <!– start box --> <table> <tr> <td colspan=“2”><b> Testpage </b></td> </tr> {rows} </table> <!– end box --> include(&quot;./template.inc&quot;); $t = new Template(&quot;/page/to/webserver/template&quot;, &quot;keep&quot;); // define variables named page and box, referencing files $t->set_file(array( &quot;page&quot; => &quot;page.ihtml&quot;, &quot;box&quot; => &quot;box.ihtml&quot;)); // define variable TITLE and PAGETITLE $t->set_var(array(&quot;TITLE&quot; => &quot;Testpage&quot;, &quot;PAGETITLE&quot; => “ test &quot;)); # extract the block &quot;row&quot; from &quot;box&quot;, creat e a reference to {rows}&quot;. $t->set_block(&quot;box&quot;, &quot;row&quot;, &quot;rows&quot;); # define NUM and BIGNUM, then append &quot;row&quot; to &quot;rows&quot;... for ($i=1; $i<=3; $i++) { $n = $i; $nn = $i*10; $t->set_var(array(&quot;NUM&quot; => $n, &quot;BIGNUM&quot; => $nn)); $t->parse(&quot;rows&quot;, &quot;row&quot;, true); } # build out from box, then build out put from page... $t->parse(&quot;OUT&quot;, &quot;box“ ); $t->parse(“Output” , &quot;page&quot;)); # finish out and print it. $t->p(&quot;OUT&quot;); ?> <tr> <td> 1 </td> <td> 10 </td> </tr> <tr> <td> 2 </td> <td> 20 </td> </tr>
  • 21. Programming techniques Template example 2 <html> <head><title> test </title></head> <body> <table> <tr><td colspan=“2”> <h1> test </h1></td></tr> <tr> <td> {OUT} </td> <td>Content</td> </tr> </table> </body> </html> <!– start box --> <table> <tr> <td colspan=“2”><b> Testpage </b></td> </tr> <tr> <td> 1 </td> <td> 10 </td> </tr> <tr> <td> 2 </td> <td> 20 </td> </tr> </table> <!– end box --> include(&quot;./template.inc&quot;); $t = new Template(&quot;/page/to/webserver/template&quot;, &quot;keep&quot;); // define variables named page and box, referencing files $t->set_file(array( &quot;page&quot; => &quot;page.ihtml&quot;, &quot;box&quot; => &quot;box.ihtml&quot;)); // define variable TITLE and PAGETITLE $t->set_var(array(&quot;TITLE&quot; => &quot;Testpage&quot;, &quot;PAGETITLE&quot; => “ test &quot;)); # extract the block &quot;row&quot; from &quot;box&quot;, creat e a reference to {rows}&quot;. $t->set_block(&quot;box&quot;, &quot;row&quot;, &quot;rows&quot;); # define NUM and BIGNUM, then append &quot;row&quot; to &quot;rows&quot;... for ($i=1; $i<=3; $i++) { $n = $i; $nn = $i*10; $t->set_var(array(&quot;NUM&quot; => $n, &quot;BIGNUM&quot; => $nn)); $t->parse(&quot;rows&quot;, &quot;row&quot;, true); } # build out from box, then build out put from page... $t->parse(&quot;OUT&quot;, &quot;box“ ); $t->parse(“Output” , &quot;page&quot;)); # finish out and print it. $t->p(&quot;O utput &quot;); ?>
  • 22. Programming techniques Template example 2 <html> <head><title> test </title></head> <body> <table> <tr><td colspan=“2”> <h1> test </h1></td></tr> <tr> <td> <table> <tr> <td colspan=“2”><b>Testpage</b></td> </tr> <tr> <td>1</td> <td>10</td> </tr> <tr> <td>2</td> <td>20</td> </tr> </table> </td> <td>Content</td> </tr> </table> </body> </html> include(&quot;./template.inc&quot;); $t = new Template(&quot;/page/to/webserver/template&quot;, &quot;keep&quot;); // define variables named page and box, referencing files $t->set_file(array( &quot;page&quot; => &quot;page.ihtml&quot;, &quot;box&quot; => &quot;box.ihtml&quot;)); // define variable TITLE and PAGETITLE $t->set_var(array(&quot;TITLE&quot; => &quot;Testpage&quot;, &quot;PAGETITLE&quot; => “ test &quot;)); # extract the block &quot;row&quot; from &quot;box&quot;, creat e a reference to {rows}&quot;. $t->set_block(&quot;box&quot;, &quot;row&quot;, &quot;rows&quot;); # define NUM and BIGNUM, then append &quot;row&quot; to &quot;rows&quot;... for ($i=1; $i<=3; $i++) { $n = $i; $nn = $i*10; $t->set_var(array(&quot;NUM&quot; => $n, &quot;BIGNUM&quot; => $nn)); $t->parse(&quot;rows&quot;, &quot;row&quot;, true); } # build out from box, then build out put from page... $t->parse(&quot;OUT&quot;, &quot;box“ ); $t->parse(“Output” , &quot;page&quot;)); # finish out and print it. $t->p(&quot;OUT&quot;); ?>
  • 23. Programming techniques Template example 2 <html> <head><title> test </title></head> <body> <table> <tr><td colspan=“2”> <h1> test </h1></td></tr> <tr> <td> <table> <tr> <td colspan=“2”><b> Testpage </b></td> </tr> <tr> <td> 1 </td> <td> 10 </td> </tr> <tr> <td> 2 </td> <td> 20 </td> </tr> </table> </td> <td>Content</td> </tr> </table> </body> </html> Content test 30 3 20 2 10 1 Testpage
  • 24.
  • 26. Handling Forms <form method=“ post ” action=“index.php”> <input type=“hidden” name=“ id ” value=“100” /> <table> <tr> <td>User</td> <td><input type=“text” name=“ user ” /></td> </tr> <tr> <td>Password</td> <td><input type=“password” name=“ passwd ” /> </td> </tr> <tr> <td colspan=“2”> <input type=“submit” name=“ Login ” value=“Login” /> </td> </tr> </table> </form>
  • 27. Handling Forms <form method=“ post ” action=“index.php”> <input type=“hidden” name=“ id ” value=“100” /> <table> <tr> <td>User</td> <td><input type=“text” name=“ user ” /></td> </tr> <tr> <td>Password</td> <td><input type=“password” name=“ passwd ” /> </td> </tr> <tr> <td colspan=“2”> <input type=“submit” name=“ Login ” value=“Login” /> </td> </tr> </table> </form> $ok = false; if (array_key_exists(“submit”, $_POST ) && ( $_POST [“submit”] == “Login”) ) { $ok = CheckLogin( $_POST [“id”], $_POST [“user”], $_POST [“passwd”]); } if ($ok) { include(“restrictedArea.html”); } else { include(“loginForm.html”); }
  • 28. Handling Forms <form method=“ get ” action=“index.php”> <input type=“hidden” name=“ id ” value=“100” /> <table> <tr> <td>User</td> <td><input type=“text” name=“ user ” /></td> </tr> <tr> <td>Password</td> <td><input type=“password” name=“ passwd ” /> </td> </tr> <tr> <td colspan=“2”> <input type=“submit” name=“ Login ” value=“Login” /> </td> </tr> </table> </form> $ok = false; if (array_key_exists(“submit”, $_ GET ) && ( $_ GET [“submit”] == “Login”) ) { $ok = CheckLogin( $_GET [“id”], $_GET [“user”], $_GET [“passwd”]); } if ($ok) { include(“restrictedArea.html”); } else { include(“loginForm.html”); }
  • 29.
  • 30.
  • 31.
  • 32. Sessions <? // Login page session_start(); // Process the login form …………………… // Login is completed $_SESSION[‘user’] = $_POST[‘user’]; $_SESSION[‘passwd’] = $_POST[‘passwd’]; // Redirect to the private page header(&quot;Location:  ”. ” http:// www.server.com/nextpage.php” ); ?> <? // next page session_start(); // Check login user if (!array_key_exists(“user”, $_SESSION)) { // No user logged in echo “You need to login first”; exit(); } echo “Hello “. $_SESSION[“user”] .”!<br/>”; ?>
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.