This document provides an overview of PHP and MySQL:
- PHP code is embedded into web pages and used to generate dynamic HTML content. It interacts with databases using MySQL.
- PHP supports variables, arrays, control structures, functions and object-oriented programming. Version 5 added improved OOP support.
- Templates can be used to separate application logic from user interface code for improved maintenance. Common techniques include using templates to modularize content.
PHP is one of the simplest server-side languages out there, and it was designed primarily for web development. Learning PHP is good not only because it adds ...
PHP is one of the simplest server-side languages out there, and it was designed primarily for web development. Learning PHP is good not only because it adds ...
These are the slides for a workshop I’ve given at a couple conferences, explaining how Twig works to people who don’t necessarily come from a programming background.
These are the slides for a workshop I’ve given at a couple conferences, explaining how Twig works to people who don’t necessarily come from a programming background.
Johannes Schlüter's PHPNW08 slides:
The current PHP version, PHP 5.3 introduced a multitude of new language features, most notably namespaces and late static binding, new extensions such as phar, as well as numerous other improvements. Even so, this power-packed release boasts better performance than older PHP releases. This talk will give you a good overview about PHP 5.3 and show some less known features in detail.
My colleague Adnan created this slide and on behalf of him i am uploading this slide.
A nice Visual Diagram is there on the SERVER CLIENT concept. Must see for newbie.
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("./template.inc"); $t = new Template("/page/to/webserver/template", "keep"); // define variables named page and box, referencing files $t->set_file(array( "page" => "page.ihtml", "box" => "box.ihtml")); // define variable TITLE and PAGETITLE $t->set_var(array("TITLE" => "Testpage", "PAGETITLE" => “ test ")); # extract the block "row" from "box", creat e a reference to {rows}". $t->set_block("box", "row", "rows"); # define NUM and BIGNUM, then append "row" to "rows"... for ($i=1; $i<=3; $i++) { $n = $i; $nn = $i*10; $t->set_var(array("NUM" => $n, "BIGNUM" => $nn)); $t->parse("rows", "row", true); } # build out from box, then build out put from page... $t->parse("OUT", "box“ ); $t->parse(“Output” , "page")); # finish out and print it. $t->p("OUT"); ?>
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("./template.inc"); $t = new Template("/page/to/webserver/template", "keep"); // define variables named page and box, referencing files $t->set_file(array( "page" => "page.ihtml", "box" => "box.ihtml")); // define variable TITLE and PAGETITLE $t->set_var(array("TITLE" => "Testpage", "PAGETITLE" => “ test ")); # extract the block "row" from "box", creat e a reference to {rows}". $t->set_block("box", "row", "rows"); # define NUM and BIGNUM, then append "row" to "rows"... for ($i=1; $i<=3; $i++) { $n = $i; $nn = $i*10; $t->set_var(array("NUM" => $n, "BIGNUM" => $nn)); $t->parse("rows", "row", true); } # build out from box, then build out put from page... $t->parse("OUT", "box“ ); $t->parse(“Output” , "page")); # finish out and print it. $t->p("OUT"); ?>
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("./template.inc"); $t = new Template("/page/to/webserver/template", "keep"); // define variables named page and box, referencing files $t->set_file(array( "page" => "page.ihtml", "box" => "box.ihtml")); // define variable TITLE and PAGETITLE $t->set_var(array("TITLE" => "Testpage", "PAGETITLE" => “ test ")); # extract the block "row" from "box", creat e a reference to {rows}". $t->set_block("box", "row", "rows"); # define NUM and BIGNUM, then append "row" to "rows"... for ($i=1; $i<=3; $i++) { $n = $i; $nn = $i*10; $t->set_var(array("NUM" => $n, "BIGNUM" => $nn)); $t->parse("rows", "row", true); } # build out from box, then build out put from page... $t->parse("OUT", "box“ ); $t->parse(“Output” , "page")); # finish out and print it. $t->p("OUT"); ?> <!– 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("./template.inc"); $t = new Template("/page/to/webserver/template", "keep"); // define variables named page and box, referencing files $t->set_file(array( "page" => "page.ihtml", "box" => "box.ihtml")); // define variable TITLE and PAGETITLE $t->set_var(array("TITLE" => "Testpage", "PAGETITLE" => “ test ")); # extract the block "row" from "box", creat e a reference to {rows}". $t->set_block("box", "row", "rows"); # define NUM and BIGNUM, then append "row" to "rows"... for ($i=1; $i<=3; $i++) { $n = $i; $nn = $i*10; $t->set_var(array("NUM" => $n, "BIGNUM" => $nn)); $t->parse("rows", "row", true); } # build out from box, then build out put from page... $t->parse("OUT", "box“ ); $t->parse(“Output” , "page")); # finish out and print it. $t->p("OUT"); ?> <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("./template.inc"); $t = new Template("/page/to/webserver/template", "keep"); // define variables named page and box, referencing files $t->set_file(array( "page" => "page.ihtml", "box" => "box.ihtml")); // define variable TITLE and PAGETITLE $t->set_var(array("TITLE" => "Testpage", "PAGETITLE" => “ test ")); # extract the block "row" from "box", creat e a reference to {rows}". $t->set_block("box", "row", "rows"); # define NUM and BIGNUM, then append "row" to "rows"... for ($i=1; $i<=3; $i++) { $n = $i; $nn = $i*10; $t->set_var(array("NUM" => $n, "BIGNUM" => $nn)); $t->parse("rows", "row", true); } # build out from box, then build out put from page... $t->parse("OUT", "box“ ); $t->parse(“Output” , "page")); # finish out and print it. $t->p("OUT"); ?> <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("./template.inc"); $t = new Template("/page/to/webserver/template", "keep"); // define variables named page and box, referencing files $t->set_file(array( "page" => "page.ihtml", "box" => "box.ihtml")); // define variable TITLE and PAGETITLE $t->set_var(array("TITLE" => "Testpage", "PAGETITLE" => “ test ")); # extract the block "row" from "box", creat e a reference to {rows}". $t->set_block("box", "row", "rows"); # define NUM and BIGNUM, then append "row" to "rows"... for ($i=1; $i<=3; $i++) { $n = $i; $nn = $i*10; $t->set_var(array("NUM" => $n, "BIGNUM" => $nn)); $t->parse("rows", "row", true); } # build out from box, then build out put from page... $t->parse("OUT", "box“ ); $t->parse(“Output” , "page")); # finish out and print it. $t->p("O utput "); ?>
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("./template.inc"); $t = new Template("/page/to/webserver/template", "keep"); // define variables named page and box, referencing files $t->set_file(array( "page" => "page.ihtml", "box" => "box.ihtml")); // define variable TITLE and PAGETITLE $t->set_var(array("TITLE" => "Testpage", "PAGETITLE" => “ test ")); # extract the block "row" from "box", creat e a reference to {rows}". $t->set_block("box", "row", "rows"); # define NUM and BIGNUM, then append "row" to "rows"... for ($i=1; $i<=3; $i++) { $n = $i; $nn = $i*10; $t->set_var(array("NUM" => $n, "BIGNUM" => $nn)); $t->parse("rows", "row", true); } # build out from box, then build out put from page... $t->parse("OUT", "box“ ); $t->parse(“Output” , "page")); # finish out and print it. $t->p("OUT"); ?>
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("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/>”; ?>