SlideShare a Scribd company logo
Muhammad Abdur Rahman AdnaN jhoroTEK.com [email_address]
COMP519: Web Programming   (University of Liverpool) http://www.csc.liv.ac.uk/~martin/teaching/comp519/ Teach Yourself Ajax in 10 Minutes, Phil Ballard, Sams Publishing, 2006 http://www.w3schools.com
Linux, Apache, MySQL, PHP Pack You Can  Download PHP for free here: http://www.php.net MySQL for free here: http://www.mysql.com Apache for free here: http://httpd.apache.org
Some Idea of HTML, XHTML Some Scripting Knowledge Some SQL Knowledge
Web Page (Client) Web Servers (Server) Server-Side Programming Web Browsers Client-Side Programming
H yper  T ext  M arkup  L anguage View in Client Side C ascading  S tyle  S heets Visual Representation property only Some what Client Side Manipulation with JavaScript
 
By default, HTML and web servers don’t keep track of information entered on a page when the client’s browser opens another page.  Thus, doing anything involving the same information across several pages can sometimes be difficult.
a  cookie  is a collection of information about the user Stored in browser server can set a cookie to the client’s machine using the “Set-cookie” header in a response Set-cookie: CUSTOMER=Dave_Reed; PATH=/; EXPIRES=Thursday, 29-Jan-04 12:00:00 when user returns to URL on the specified path, the browser returns the cookie data as part of its request Cookie: CUSTOMER=Dave_Reed
Session solves this problem by storing user information on the server for later use Its Temporary & customable timeframe Deleted after the user has left the website Creates a unique id (UID) per user
an HTML document has two main structural elements HEAD contains setup information for the browser & the Web page e.g., the title for the browser window, style definitions, JavaScript code, … BODY contains the actual content to be displayed in the Web page <html> <!–-  Version information  -- --  File: page01.html  -- --  Author: COMP519  -- --  Creation: 15.08.06 -- --  Description: introductory page  -- --  Copyright: U.Liverpool  -- --> <head> <title> My first HTML document </title> </head> <body> Hello world! </body> </html> HTML documents begin and end with   <html>   and   </html>   tags Comments appear between   <!--   and   --> HEAD  section enclosed between   <head>   and   </head> BODY  section enclosed between   <body>   and   </body>
To add many new 'interactive' features Feedback forms Guest books Message boards (Forums) Counters Advanced  features Portal systems Content management Advertising managers
The Common Gateway Interface  (CGI) Perl,  C, C++,  Ruby,  Python Other asp,  jsp,  Coldfusion, PHP
Setting individual Items Or Best if we use available packs For LAMP XAMPP  Pack Download Free From: http://www.apachefriends.org/en/xampp.html For WAMP (yes windows) UniServer Pack Download Free From: http://www.uniformserver.com
PHP stands for  P HP:  H ypertext  P reprocessor  PHP code is embedded in HTML using tags When a page request arrives, the server recognizes PHP content via the file extension ( .php   or  .phtml ) The server executes the PHP code, substitutes output into the HTML The resulting page is then downloaded to the client User never sees the PHP code, only the output in the page
A PHP scripting block starts with  <?php  and ends with  ?> .  A scripting block can be placed anywhere in HTML. <html> <!-- hello.php COMP519 --> <head><title>Hello World</title></head> <body> <p>This is going to be ignored by the PHP interpreter.</p> <?php   echo  ‘<p>While this is going to be parsed.</p>‘;  ?> <p>This will also be ignored by PHP.</p> <?php   print( ‘ <p> Hello and welcome to <i>my</i> page!</p> ' ) ;  ?> <? php // This is a comment /* This is a comment block */ ?> </body> </html>  The server executes the print and echo statements, substitutes output. print  and  echo for output a semicolon (;)  at the end of each statement (can be omitted at the end of block/file) //  for a single-line comment /*  and  */   for a large comment block.
All variables in PHP start with a  $  sign symbol. A variable's type is determined by the context in which that variable is used  (i.e. there is no strong-typing in PHP). <html><head></head> <!-- scalars.php COMP519 --> <body>  <p> <?php $foo = True; if ($foo) echo &quot;It is TRUE! <br /> \n&quot;; $txt='1234'; echo &quot;$txt <br /> \n&quot;; $a = 1234; echo &quot;$a <br /> \n&quot;; $a = -123;  echo &quot;$a <br /> \n&quot;; $a = 1.234;  echo &quot;$a <br /> \n&quot;; $a = 1.2e3;  echo &quot;$a <br /> \n&quot;; $a = 7E-10;  echo &quot;$a <br /> \n&quot;; echo 'Arnold once said: &quot;I\'ll be back&quot;', &quot;<br /> \n&quot;; $beer = 'Heineken';  echo &quot;$beer's taste is great <br /> \n&quot;; ?>  </p> </body> </html> Four scalar types:  boolean  TRUE or FALSE integer,  just numbers float  float point numbers string  single quoted double quoted
Arrays An array in PHP is actually an ordered map. A map is a type that maps values to keys. <?php $arr = array(&quot;foo&quot; => &quot;bar&quot;, 12 => true); echo $arr[&quot;foo&quot;]; // bar echo $arr[12];  // 1 ?> key  = either an integer or a string.  value  = any PHP type. <?php $arr = array(5 => 1, 12 => 2); $arr[] = 56;  // the same as $arr[13] = 56; $arr[&quot;x&quot;] = 42; // adds a new element unset($arr[5]); // removes the element unset($arr);  // deletes the whole array $a = array(1 => 'one', 2 => 'two', 3 => 'three'); unset($a[2]); $b = array_values($a); ?> can set values in an array unset()  removes a key/value pair *Find more on arrays array_values()  makes reindex effect (indexing numerically) Arrays An array in PHP is actually an ordered map. A map is a type that maps values to keys. array()  = creates arrays <?php $arr = array(&quot;foo&quot; => &quot;bar&quot;, 12 => true); echo $arr[&quot;foo&quot;]; // bar echo $arr[12];  // 1 ?> <?php array(5 => 43, 32, 56, &quot;b&quot; => 12); array(5 => 43, 6 => 32, 7 => 56, &quot;b&quot; => 12); ?> if  no key , the maximum of the integer indices + 1.  if  an existing key , its value will be overwritten. <?php array(5 => 43, 32, 56, &quot;b&quot; => 12); array(5 => 43, 6 => 32, 7 => 56, &quot;b&quot; => 12); ?> if  no key , the maximum of the integer indices + 1.  if  an existing key , its value will be overwritten. <?php $arr = array(5 => 1, 12 => 2); $arr[] = 56;  // the same as $arr[13] = 56; $arr[&quot;x&quot;] = 42; // adds a new element unset($arr[5]); // removes the element unset($arr);  // deletes the whole array $a = array(1 => 'one', 2 => 'two', 3 => 'three'); unset($a[2]); $b = array_values($a); ?> can set values in an array unset()  removes a key/value pair *Find more on arrays array_values()  makes reindex effect (indexing numerically)
Operators Arithmetic Operators:   +, -, *,/ , %, ++, -- Assignment Operators:   =, +=, -=, *=, /=, %= Comparison Operators:   ==, !=, >, <, >=, <=   Logical Operators:   &&, ||, ! String Operators :  . , .= Example   Is the same as x+=y   x=x+y x-=y   x=x-y x*=y   x=x*y x/=y   x=x/y x%=y   x=x%y $a = &quot;Hello &quot;; $b = $a . &quot;World!&quot;; // now $b contains &quot;Hello World!&quot; $a = &quot;Hello &quot;; $a .= &quot;World!&quot;;
Conditionals: if else Can execute a set of code depending on a condition <html><head></head> <!-- if-cond.php COMP519 --> <body> <?php $d=date(&quot;D&quot;); if  ( $d==&quot;Fri&quot; ) echo &quot;Have a nice weekend! <br/>&quot;;  else echo &quot;Have a nice day! <br/>&quot;;  $x=10; if ($x==10) { echo &quot;Hello<br />&quot;;  echo &quot;Good morning<br />&quot;; } ?> </body> </html> if ( condition ) code to be executed if condition is  true ; else code to be executed if condition is  false ; date()  is a built-in function that can be called with many different parameters to return the date (and/or local time) in various formats In this case we get a three letter string for the day of the week.
Can loop depending on a condition <html><head></head> <body> <?php  $i=1; while ( $i <= 5 ) { echo &quot;The number is $i <br />&quot;; $i++; } ?> </body> </html> loops through a block of code if and as long as a specified condition is true <html><head></head> <body> <?php  $i=0; do { $i++; echo &quot;The number is $i <br />&quot;; } while ( $i <= 10 ); ?> </body> </html> loops through a block of code once, and then repeats the loop as long as a special condition is true
Can loop depending on a &quot;counter&quot; <?php for   ($i=1; $i<=5; $i++) { echo &quot;Hello World!<br />&quot;; } ?> loops through a block of code a specified number of times <?php $a_array = array(1, 2, 3, 4); foreach   ($a_array as $value)   { $value = $value * 2; echo “$value <br/> \n”; } ?> loops through a block of code for each element in an array <?php  $a_array=array(&quot;a&quot;,&quot;b&quot;,&quot;c&quot;); foreach  ($a_array as $key=>$value) { echo $key.&quot; = &quot;.$value.&quot;\n&quot;; } ?>
Can define a function using syntax such as the following: <?php function  foo( $arg_1 ,  $arg_2 , /* ..., */  $arg_n ) { echo &quot;Example function.\n&quot;; return   $retval ; } ?> Can also define conditional functions, functions within functions, and recursive functions. Can return a value of any type <?php function  takes_array( $input ) { echo &quot;$input[0] + $input[1] = &quot;, $input[0]+$input[1]; } takes_array(array(1,2)); ?> <?php function  square( $num ) { return   $num * $num ; } echo square( 4 ); ?> <?php function  small_numbers() { return  array (0, 1, 2); } list ($zero, $one, $two) = small_numbers(); echo $zero, $one, $two; ?>
The scope of a variable is the context within which it is defined. <?php $a = 1; /* global scope */  function Test() {  echo $a;  /* reference to local scope variable */  }  Test(); ?> The scope is local within functions. <?php $a = 1; $b = 2; function Sum() { global  $a, $b; $b = $a + $b; }  Sum(); echo $b; ?> global refers to its global version. <?php function Test() { static $a = 0; echo $a; $a++; } Test1();  Test1(); Test1(); ?> static   does not lose its value.
Absolute File Path Relative File Path
The  include()  statement includes and evaluates the specified file. vars.php <?php $color = 'green'; $fruit = 'apple'; ?> test.php <?php echo &quot;A $color $fruit&quot;; //  A include  ' vars.php '; echo &quot;A $color $fruit&quot;; //  A green  apple ?> *The scope of variables in “included” files depends on where the “include” file is added! You can use the include_once, require, and require_once statements in similar ways .  <?php function foo() { global $color; include   ('vars.php‘); echo &quot;A $color $fruit&quot;; } /* vars.php is in the scope of foo() so  * * $fruit is NOT available outside of this  * * scope.  $color is because we declared it * * as global.   */ foo();  //  A green apple echo &quot;A $color $fruit&quot;;  //  A green ?>
The  fopen( &quot;file_name&quot; , &quot;mode&quot; )  function is used to open files in PHP. <?php $fh = fopen( &quot;welcome.txt&quot; ,&quot;r&quot; ) ; ?> r Read only.   r+ Read/Write. w Write only.   w+ Read/Write.   a Append.   a+ Read/Append. x Create and open for write only.   x+ Create and open for read/write. If the  fopen()  function is unable to open the specified file, it returns 0 (false). <?php if (!( $fh = fopen( &quot;welcome.txt&quot; ,&quot;r&quot; ) )) exit(&quot;Unable to open file!&quot;);  ?> For  w , and  a , if no file exists, it tries to create it (use with caution, i.e. check that this is the case, otherwise you’ll overwrite an existing file). For  x  if a file exists, it returns an error.
Any form element is automatically available via one of the built-in PHP variables. <html> <-- form.html COMP519 --> <body> <form action=&quot; welcome.php &quot; method=&quot; POST &quot;> Enter your name: <input type=&quot;text&quot; name= &quot;name&quot;  /> <br/> Enter your age: <input type=&quot;text&quot; name= &quot;age&quot;  /> <br/> <input type=&quot;submit&quot; /> <input type=&quot;reset&quot; /> </form> </body> </html> <html> <!–-  welcome.php  COMP 519 --> <body> Welcome <?php echo  $_POST[ &quot;name&quot; ].”.” ; ?><br /> You are <?php echo  $_POST[ &quot;age&quot; ] ; ?> years old! </body> </html> $_POST   contains all POST data.   $_GET   contains all GET data. $_REQUEST   contains all GET & POST data.
setcookie( name , value , expire , path , domain )   creates cookies. <?php  setcookie( &quot;uname&quot; , $_POST[ &quot;name&quot; ], time()+36000 ) ; ?> <html> <body> <p> Dear <?php echo $_POST[ &quot;name&quot; ] ?>, a cookie was set on this page! The cookie will be active when the client has sent the cookie back to the server. </p> </body> </html> NOTE: setcookie()   must appear  BEFORE  <html>  (or any output)   as it’s part of the header information sent with the page.  <html> <body> <?php if ( isset($_COOKIE[ &quot;uname&quot; ]) ) echo &quot;Welcome &quot; .  $_COOKIE[ &quot;uname&quot; ]  . &quot;!<br />&quot;; else echo &quot;You are not logged in!<br />&quot;; ?> </body> </html> use the cookie name as a variable isset() finds out if a cookie is set $_COOKIE contains all COOKIE data.
Before storing user information,  must first start up the session. <?php  session_start();  // store session data  $_SESSION['views']=1;  ?>  <html><body>  <?php  //retrieve session data  echo &quot;Pageviews=&quot;. $_SESSION['views'];  ?>  </body> </html>  NOTE: session_start()   must appear  BEFORE  <html>  (or any output)   as it’s part of the header information sent with the page.  <?php session_start();  if(isset($_SESSION['views'])) $_SESSION['views']=$_SESSION['views']+1; else $_SESSION['views']=1; echo &quot;Views=&quot;. $_SESSION['views'];  ?> use the session name as a variable isset() finds out if a session is set $_SESSION contains all SESSION data.
<?php session_destroy();  ?>  NOTE: session_destroy()   will remove all the stored data in session for current user.  Mostly used when logged out from a site. <?php unset($_SESSION['views']);  ?> unset() removes a data from session
date() and time ()  formats a time or a date. <?php //Prints something like: Monday echo  date(&quot;l&quot;); //Like: Monday 15th of January 2003 05:51:38 AM echo  date(&quot;l dS of F Y h:i:s A&quot;); //Like: Monday the 15th echo  date(&quot;l \\t\h\e jS&quot;); ?> date()  returns a string formatted according to the specified format. *Here is more on date/time formats:  http://php.net/date <?php $nextWeek =  time()  + (7 * 24 * 60 * 60); // 7 days; 24 hours; 60 mins; 60secs echo 'Now:  '.  date('Y-m-d')  .&quot;\n&quot;; echo 'Next Week: '.  date('Y-m-d', $nextWeek)  .&quot;\n&quot;; ?> time()  returns current Unix timestamp
In the this lecture you have learned HTTP Work Flow Cookie & Session What is PHP and what are some of its workings.  Basic PHP syntax variables, operators, if...else...and switch,  while, do while, and for. Some useful PHP functions How to work with  HTML forms, cookies, sessions, files, time and date.
 

More Related Content

What's hot (20)

PDF
Extending the WordPress REST API - Josh Pollock
Caldera Labs
 
PDF
Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
Caldera Labs
 
PPTX
Dev traning 2016 basics of PHP
Sacheen Dhanjie
 
PPT
PHP - Introduction to PHP
Vibrant Technologies & Computers
 
PDF
RESTful web services
Tudor Constantin
 
PPTX
Constructor and encapsulation in php
SHIVANI SONI
 
PPT
PHP POWERPOINT SLIDES
Ismail Mukiibi
 
PPT
Create a web-app with Cgi Appplication
olegmmiller
 
PPTX
Introduction to PHP
Collaboration Technologies
 
PPT
Class 6 - PHP Web Programming
Ahmed Swilam
 
PPT
PHP Tutorials
Yuriy Krapivko
 
KEY
Using PHP
Mark Casias
 
PDF
Perl in the Internet of Things
Dave Cross
 
ODP
Introduction to Web Programming with Perl
Dave Cross
 
PDF
Introduction to PHP
Bradley Holt
 
PPTX
Working with WP_Query in WordPress
topher1kenobe
 
PDF
Developing apps using Perl
Anatoly Sharifulin
 
PPTX
Webinar: AngularJS and the WordPress REST API
WP Engine UK
 
PPT
Introduction To PHP
Shweta A
 
PPTX
New in php 7
Vic Metcalfe
 
Extending the WordPress REST API - Josh Pollock
Caldera Labs
 
Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
Caldera Labs
 
Dev traning 2016 basics of PHP
Sacheen Dhanjie
 
PHP - Introduction to PHP
Vibrant Technologies & Computers
 
RESTful web services
Tudor Constantin
 
Constructor and encapsulation in php
SHIVANI SONI
 
PHP POWERPOINT SLIDES
Ismail Mukiibi
 
Create a web-app with Cgi Appplication
olegmmiller
 
Introduction to PHP
Collaboration Technologies
 
Class 6 - PHP Web Programming
Ahmed Swilam
 
PHP Tutorials
Yuriy Krapivko
 
Using PHP
Mark Casias
 
Perl in the Internet of Things
Dave Cross
 
Introduction to Web Programming with Perl
Dave Cross
 
Introduction to PHP
Bradley Holt
 
Working with WP_Query in WordPress
topher1kenobe
 
Developing apps using Perl
Anatoly Sharifulin
 
Webinar: AngularJS and the WordPress REST API
WP Engine UK
 
Introduction To PHP
Shweta A
 
New in php 7
Vic Metcalfe
 

Similar to Introduction To Lamp (20)

PPT
Web development
Seerat Bakhtawar
 
PPT
Php Crash Course
mussawir20
 
PPT
PHP Workshop Notes
Pamela Fox
 
PPT
Introduction to PHP
Jussi Pohjolainen
 
PPT
What Is Php
AVC
 
PPT
Introduction To Php For Wit2009
cwarren
 
PPT
Php Chapter 1 Training
Chris Chubb
 
PPT
PHP
webhostingguy
 
PPT
course slides -- powerpoint
webhostingguy
 
PPT
Open Source Package Php Mysql 1228203701094763 9
isadorta
 
PPT
Open Source Package PHP & MySQL
kalaisai
 
PPT
PHP MySQL
Md. Sirajus Salayhin
 
PPT
Internet Technology and its Applications
amichoksi
 
PPT
Php Basic
Md. Sirajus Salayhin
 
PPT
Basic PHP
Todd Barber
 
PPT
P H P Part I, By Kian
phelios
 
PPTX
PHP Powerpoint -- Teach PHP with this
Ian Macali
 
PPT
Control Structures In Php 2
Digital Insights - Digital Marketing Agency
 
PPT
Phpwebdevelping
mohamed ashraf
 
PPT
Building an e:commerce site with PHP
webhostingguy
 
Web development
Seerat Bakhtawar
 
Php Crash Course
mussawir20
 
PHP Workshop Notes
Pamela Fox
 
Introduction to PHP
Jussi Pohjolainen
 
What Is Php
AVC
 
Introduction To Php For Wit2009
cwarren
 
Php Chapter 1 Training
Chris Chubb
 
course slides -- powerpoint
webhostingguy
 
Open Source Package Php Mysql 1228203701094763 9
isadorta
 
Open Source Package PHP & MySQL
kalaisai
 
Internet Technology and its Applications
amichoksi
 
Basic PHP
Todd Barber
 
P H P Part I, By Kian
phelios
 
PHP Powerpoint -- Teach PHP with this
Ian Macali
 
Control Structures In Php 2
Digital Insights - Digital Marketing Agency
 
Phpwebdevelping
mohamed ashraf
 
Building an e:commerce site with PHP
webhostingguy
 
Ad

Recently uploaded (20)

PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
infertility, types,causes, impact, and management
Ritu480198
 
PPTX
Controller Request and Response in Odoo18
Celine George
 
PDF
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
PPTX
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
Introduction to Indian Writing in English
Trushali Dodiya
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PDF
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
PDF
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
PDF
Introduction presentation of the patentbutler tool
MIPLM
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
infertility, types,causes, impact, and management
Ritu480198
 
Controller Request and Response in Odoo18
Celine George
 
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Introduction to Indian Writing in English
Trushali Dodiya
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
Introduction presentation of the patentbutler tool
MIPLM
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
Ad

Introduction To Lamp

  • 1. Muhammad Abdur Rahman AdnaN jhoroTEK.com [email_address]
  • 2. COMP519: Web Programming (University of Liverpool) http://www.csc.liv.ac.uk/~martin/teaching/comp519/ Teach Yourself Ajax in 10 Minutes, Phil Ballard, Sams Publishing, 2006 http://www.w3schools.com
  • 3. Linux, Apache, MySQL, PHP Pack You Can Download PHP for free here: http://www.php.net MySQL for free here: http://www.mysql.com Apache for free here: http://httpd.apache.org
  • 4. Some Idea of HTML, XHTML Some Scripting Knowledge Some SQL Knowledge
  • 5. Web Page (Client) Web Servers (Server) Server-Side Programming Web Browsers Client-Side Programming
  • 6. H yper T ext M arkup L anguage View in Client Side C ascading S tyle S heets Visual Representation property only Some what Client Side Manipulation with JavaScript
  • 7.  
  • 8. By default, HTML and web servers don’t keep track of information entered on a page when the client’s browser opens another page. Thus, doing anything involving the same information across several pages can sometimes be difficult.
  • 9. a cookie is a collection of information about the user Stored in browser server can set a cookie to the client’s machine using the “Set-cookie” header in a response Set-cookie: CUSTOMER=Dave_Reed; PATH=/; EXPIRES=Thursday, 29-Jan-04 12:00:00 when user returns to URL on the specified path, the browser returns the cookie data as part of its request Cookie: CUSTOMER=Dave_Reed
  • 10. Session solves this problem by storing user information on the server for later use Its Temporary & customable timeframe Deleted after the user has left the website Creates a unique id (UID) per user
  • 11. an HTML document has two main structural elements HEAD contains setup information for the browser & the Web page e.g., the title for the browser window, style definitions, JavaScript code, … BODY contains the actual content to be displayed in the Web page <html> <!–- Version information -- -- File: page01.html -- -- Author: COMP519 -- -- Creation: 15.08.06 -- -- Description: introductory page -- -- Copyright: U.Liverpool -- --> <head> <title> My first HTML document </title> </head> <body> Hello world! </body> </html> HTML documents begin and end with <html> and </html> tags Comments appear between <!-- and --> HEAD section enclosed between <head> and </head> BODY section enclosed between <body> and </body>
  • 12. To add many new 'interactive' features Feedback forms Guest books Message boards (Forums) Counters Advanced features Portal systems Content management Advertising managers
  • 13. The Common Gateway Interface (CGI) Perl, C, C++, Ruby, Python Other asp, jsp, Coldfusion, PHP
  • 14. Setting individual Items Or Best if we use available packs For LAMP XAMPP Pack Download Free From: http://www.apachefriends.org/en/xampp.html For WAMP (yes windows) UniServer Pack Download Free From: http://www.uniformserver.com
  • 15. PHP stands for P HP: H ypertext P reprocessor PHP code is embedded in HTML using tags When a page request arrives, the server recognizes PHP content via the file extension ( .php or .phtml ) The server executes the PHP code, substitutes output into the HTML The resulting page is then downloaded to the client User never sees the PHP code, only the output in the page
  • 16. A PHP scripting block starts with <?php and ends with ?> . A scripting block can be placed anywhere in HTML. <html> <!-- hello.php COMP519 --> <head><title>Hello World</title></head> <body> <p>This is going to be ignored by the PHP interpreter.</p> <?php echo ‘<p>While this is going to be parsed.</p>‘; ?> <p>This will also be ignored by PHP.</p> <?php print( ‘ <p> Hello and welcome to <i>my</i> page!</p> ' ) ; ?> <? php // This is a comment /* This is a comment block */ ?> </body> </html> The server executes the print and echo statements, substitutes output. print and echo for output a semicolon (;) at the end of each statement (can be omitted at the end of block/file) // for a single-line comment /* and */ for a large comment block.
  • 17. All variables in PHP start with a $ sign symbol. A variable's type is determined by the context in which that variable is used (i.e. there is no strong-typing in PHP). <html><head></head> <!-- scalars.php COMP519 --> <body> <p> <?php $foo = True; if ($foo) echo &quot;It is TRUE! <br /> \n&quot;; $txt='1234'; echo &quot;$txt <br /> \n&quot;; $a = 1234; echo &quot;$a <br /> \n&quot;; $a = -123; echo &quot;$a <br /> \n&quot;; $a = 1.234; echo &quot;$a <br /> \n&quot;; $a = 1.2e3; echo &quot;$a <br /> \n&quot;; $a = 7E-10; echo &quot;$a <br /> \n&quot;; echo 'Arnold once said: &quot;I\'ll be back&quot;', &quot;<br /> \n&quot;; $beer = 'Heineken'; echo &quot;$beer's taste is great <br /> \n&quot;; ?> </p> </body> </html> Four scalar types: boolean TRUE or FALSE integer, just numbers float float point numbers string single quoted double quoted
  • 18. Arrays An array in PHP is actually an ordered map. A map is a type that maps values to keys. <?php $arr = array(&quot;foo&quot; => &quot;bar&quot;, 12 => true); echo $arr[&quot;foo&quot;]; // bar echo $arr[12]; // 1 ?> key = either an integer or a string. value = any PHP type. <?php $arr = array(5 => 1, 12 => 2); $arr[] = 56; // the same as $arr[13] = 56; $arr[&quot;x&quot;] = 42; // adds a new element unset($arr[5]); // removes the element unset($arr); // deletes the whole array $a = array(1 => 'one', 2 => 'two', 3 => 'three'); unset($a[2]); $b = array_values($a); ?> can set values in an array unset() removes a key/value pair *Find more on arrays array_values() makes reindex effect (indexing numerically) Arrays An array in PHP is actually an ordered map. A map is a type that maps values to keys. array() = creates arrays <?php $arr = array(&quot;foo&quot; => &quot;bar&quot;, 12 => true); echo $arr[&quot;foo&quot;]; // bar echo $arr[12]; // 1 ?> <?php array(5 => 43, 32, 56, &quot;b&quot; => 12); array(5 => 43, 6 => 32, 7 => 56, &quot;b&quot; => 12); ?> if no key , the maximum of the integer indices + 1. if an existing key , its value will be overwritten. <?php array(5 => 43, 32, 56, &quot;b&quot; => 12); array(5 => 43, 6 => 32, 7 => 56, &quot;b&quot; => 12); ?> if no key , the maximum of the integer indices + 1. if an existing key , its value will be overwritten. <?php $arr = array(5 => 1, 12 => 2); $arr[] = 56; // the same as $arr[13] = 56; $arr[&quot;x&quot;] = 42; // adds a new element unset($arr[5]); // removes the element unset($arr); // deletes the whole array $a = array(1 => 'one', 2 => 'two', 3 => 'three'); unset($a[2]); $b = array_values($a); ?> can set values in an array unset() removes a key/value pair *Find more on arrays array_values() makes reindex effect (indexing numerically)
  • 19. Operators Arithmetic Operators: +, -, *,/ , %, ++, -- Assignment Operators: =, +=, -=, *=, /=, %= Comparison Operators: ==, !=, >, <, >=, <= Logical Operators: &&, ||, ! String Operators : . , .= Example Is the same as x+=y x=x+y x-=y x=x-y x*=y x=x*y x/=y x=x/y x%=y x=x%y $a = &quot;Hello &quot;; $b = $a . &quot;World!&quot;; // now $b contains &quot;Hello World!&quot; $a = &quot;Hello &quot;; $a .= &quot;World!&quot;;
  • 20. Conditionals: if else Can execute a set of code depending on a condition <html><head></head> <!-- if-cond.php COMP519 --> <body> <?php $d=date(&quot;D&quot;); if ( $d==&quot;Fri&quot; ) echo &quot;Have a nice weekend! <br/>&quot;; else echo &quot;Have a nice day! <br/>&quot;; $x=10; if ($x==10) { echo &quot;Hello<br />&quot;; echo &quot;Good morning<br />&quot;; } ?> </body> </html> if ( condition ) code to be executed if condition is true ; else code to be executed if condition is false ; date() is a built-in function that can be called with many different parameters to return the date (and/or local time) in various formats In this case we get a three letter string for the day of the week.
  • 21. Can loop depending on a condition <html><head></head> <body> <?php $i=1; while ( $i <= 5 ) { echo &quot;The number is $i <br />&quot;; $i++; } ?> </body> </html> loops through a block of code if and as long as a specified condition is true <html><head></head> <body> <?php $i=0; do { $i++; echo &quot;The number is $i <br />&quot;; } while ( $i <= 10 ); ?> </body> </html> loops through a block of code once, and then repeats the loop as long as a special condition is true
  • 22. Can loop depending on a &quot;counter&quot; <?php for ($i=1; $i<=5; $i++) { echo &quot;Hello World!<br />&quot;; } ?> loops through a block of code a specified number of times <?php $a_array = array(1, 2, 3, 4); foreach ($a_array as $value) { $value = $value * 2; echo “$value <br/> \n”; } ?> loops through a block of code for each element in an array <?php $a_array=array(&quot;a&quot;,&quot;b&quot;,&quot;c&quot;); foreach ($a_array as $key=>$value) { echo $key.&quot; = &quot;.$value.&quot;\n&quot;; } ?>
  • 23. Can define a function using syntax such as the following: <?php function foo( $arg_1 , $arg_2 , /* ..., */ $arg_n ) { echo &quot;Example function.\n&quot;; return $retval ; } ?> Can also define conditional functions, functions within functions, and recursive functions. Can return a value of any type <?php function takes_array( $input ) { echo &quot;$input[0] + $input[1] = &quot;, $input[0]+$input[1]; } takes_array(array(1,2)); ?> <?php function square( $num ) { return $num * $num ; } echo square( 4 ); ?> <?php function small_numbers() { return array (0, 1, 2); } list ($zero, $one, $two) = small_numbers(); echo $zero, $one, $two; ?>
  • 24. The scope of a variable is the context within which it is defined. <?php $a = 1; /* global scope */ function Test() { echo $a; /* reference to local scope variable */ } Test(); ?> The scope is local within functions. <?php $a = 1; $b = 2; function Sum() { global $a, $b; $b = $a + $b; } Sum(); echo $b; ?> global refers to its global version. <?php function Test() { static $a = 0; echo $a; $a++; } Test1(); Test1(); Test1(); ?> static does not lose its value.
  • 25. Absolute File Path Relative File Path
  • 26. The include() statement includes and evaluates the specified file. vars.php <?php $color = 'green'; $fruit = 'apple'; ?> test.php <?php echo &quot;A $color $fruit&quot;; // A include ' vars.php '; echo &quot;A $color $fruit&quot;; // A green apple ?> *The scope of variables in “included” files depends on where the “include” file is added! You can use the include_once, require, and require_once statements in similar ways . <?php function foo() { global $color; include ('vars.php‘); echo &quot;A $color $fruit&quot;; } /* vars.php is in the scope of foo() so * * $fruit is NOT available outside of this * * scope. $color is because we declared it * * as global. */ foo(); // A green apple echo &quot;A $color $fruit&quot;; // A green ?>
  • 27. The fopen( &quot;file_name&quot; , &quot;mode&quot; ) function is used to open files in PHP. <?php $fh = fopen( &quot;welcome.txt&quot; ,&quot;r&quot; ) ; ?> r Read only. r+ Read/Write. w Write only. w+ Read/Write. a Append. a+ Read/Append. x Create and open for write only. x+ Create and open for read/write. If the fopen() function is unable to open the specified file, it returns 0 (false). <?php if (!( $fh = fopen( &quot;welcome.txt&quot; ,&quot;r&quot; ) )) exit(&quot;Unable to open file!&quot;); ?> For w , and a , if no file exists, it tries to create it (use with caution, i.e. check that this is the case, otherwise you’ll overwrite an existing file). For x if a file exists, it returns an error.
  • 28. Any form element is automatically available via one of the built-in PHP variables. <html> <-- form.html COMP519 --> <body> <form action=&quot; welcome.php &quot; method=&quot; POST &quot;> Enter your name: <input type=&quot;text&quot; name= &quot;name&quot; /> <br/> Enter your age: <input type=&quot;text&quot; name= &quot;age&quot; /> <br/> <input type=&quot;submit&quot; /> <input type=&quot;reset&quot; /> </form> </body> </html> <html> <!–- welcome.php COMP 519 --> <body> Welcome <?php echo $_POST[ &quot;name&quot; ].”.” ; ?><br /> You are <?php echo $_POST[ &quot;age&quot; ] ; ?> years old! </body> </html> $_POST contains all POST data. $_GET contains all GET data. $_REQUEST contains all GET & POST data.
  • 29. setcookie( name , value , expire , path , domain ) creates cookies. <?php setcookie( &quot;uname&quot; , $_POST[ &quot;name&quot; ], time()+36000 ) ; ?> <html> <body> <p> Dear <?php echo $_POST[ &quot;name&quot; ] ?>, a cookie was set on this page! The cookie will be active when the client has sent the cookie back to the server. </p> </body> </html> NOTE: setcookie() must appear BEFORE <html> (or any output) as it’s part of the header information sent with the page. <html> <body> <?php if ( isset($_COOKIE[ &quot;uname&quot; ]) ) echo &quot;Welcome &quot; . $_COOKIE[ &quot;uname&quot; ] . &quot;!<br />&quot;; else echo &quot;You are not logged in!<br />&quot;; ?> </body> </html> use the cookie name as a variable isset() finds out if a cookie is set $_COOKIE contains all COOKIE data.
  • 30. Before storing user information, must first start up the session. <?php session_start(); // store session data $_SESSION['views']=1; ?> <html><body> <?php //retrieve session data echo &quot;Pageviews=&quot;. $_SESSION['views']; ?> </body> </html> NOTE: session_start() must appear BEFORE <html> (or any output) as it’s part of the header information sent with the page. <?php session_start(); if(isset($_SESSION['views'])) $_SESSION['views']=$_SESSION['views']+1; else $_SESSION['views']=1; echo &quot;Views=&quot;. $_SESSION['views']; ?> use the session name as a variable isset() finds out if a session is set $_SESSION contains all SESSION data.
  • 31. <?php session_destroy(); ?> NOTE: session_destroy() will remove all the stored data in session for current user. Mostly used when logged out from a site. <?php unset($_SESSION['views']); ?> unset() removes a data from session
  • 32. date() and time () formats a time or a date. <?php //Prints something like: Monday echo date(&quot;l&quot;); //Like: Monday 15th of January 2003 05:51:38 AM echo date(&quot;l dS of F Y h:i:s A&quot;); //Like: Monday the 15th echo date(&quot;l \\t\h\e jS&quot;); ?> date() returns a string formatted according to the specified format. *Here is more on date/time formats: http://php.net/date <?php $nextWeek = time() + (7 * 24 * 60 * 60); // 7 days; 24 hours; 60 mins; 60secs echo 'Now: '. date('Y-m-d') .&quot;\n&quot;; echo 'Next Week: '. date('Y-m-d', $nextWeek) .&quot;\n&quot;; ?> time() returns current Unix timestamp
  • 33. In the this lecture you have learned HTTP Work Flow Cookie & Session What is PHP and what are some of its workings. Basic PHP syntax variables, operators, if...else...and switch, while, do while, and for. Some useful PHP functions How to work with HTML forms, cookies, sessions, files, time and date.
  • 34.