SlideShare a Scribd company logo
1 of 96
Web Scripting using PHP
Web Scripting using PHP

   Server side scripting
So what is a Server Side Scripting Language?

• Programming language code embedded into a web
  page
                     PERL
                     PHP
                   PYTHON
                     ASP
So what is a Server Side Scripting Language?

• Programming language code embedded into a web
  page
                     PERL
                     PHP
                   PYTHON
                     ASP
Different ways of scripting the Web

• Programming language code embedded into a web
  page

           No scripting (plain markup)
              Client Side scripting
              Ser ver Side scripting
        Combination of the above (AJAX)
No Scripting example - how it works...


User on a machine somewhere




                                     Ser ver machine
Being more specific...
Web Browser soft ware
Web ser ver
soft ware
User types in a URL for a page with no
programming code inside
User types in a URL for a page with no
programming code inside




Uniform Resource Locator
Request is sent to
ser ver using HTTP
Request is sent to
                              ser ver using HTTP




Hypertext Transfer Protocol
Ser ver soft ware
finds the page
Page is sent back,
using HTTP
Browser renders /
displays the page
Server Side scripting
User types in a URL for a page with
PHP code inside
Request is sent to
ser ver using HTTP
Ser ver soft ware
finds the page
Ser ver side code
is executed
Page is sent back,
using HTTP
Browser renders /
displays the page
Server side scripting languages

 • Executes in the ser ver

 • Before the page is sent from server to browser

 • Ser ver side code is not visible in the client



 • Ser ver side code can access resources on the
   server side
Browser
            Web ser ver




          Database ser ver
How many items in stock?
HTTP request
Web ser ver
executes code
Web ser ver
    executes code




Queries
database
ser ver
Result
sent
back
HTML
generated
HTTP response
Answer displayed
So why PHP?


               PERL
               PHP
              PYTHON
               ASP
PHP usage ...




                • Source: PHP programming 2nd Ed.
PHP compared to others ...




                         • Source: www.securityspace.com
Books - core syntax




Programming PHP, Second Edition    PHP in a Nutshell

By Kevin Tatroe, Rasmus Lerdorf,   By Paul Hudson
Peter MacIntyre                    First Edition October 2005
Second Edition April 2006

** Recommended
Books - learning / tutorial based




Learning PHP 5             Learning PHP and MySQL

By David Sklar             By Michele Davis, Jon Phillips
First Edition June 2004    First Edition June 2006
Other texts..

  • There are other publishers / texts (trade books)
  • Look for books that cover PHP 5



  • Open source, server side languages can rapidly
    develop
  • Features added or deprecated rapidly
PHP development



                                        PHP 5



                           PHP 4



          PHP 3
  PHP 1




             • 5 versions in 10 years
Language basics
Language basics

    •   Embedding PHP in Web pages
    •   Whitespace and Line breaks
    •   Statements and semicolons
    •   Comments
    •   Literals / names
    •   Identifiers
    •   Keywords
    •   Data types
Language basics

    •   Embedding PHP in Web pages
    •   Whitespace and Line breaks
    •   Statements and semicolons
    •   Comments
    •   Literals / names
    •   Identifiers
    •   Keywords
    •   Data types



                    Much of this material is explained in PHP
                    programming 2nd Ed. Chap 1 & 2
Embedding PHP in web pages


                     Use <?php and ?> to
   <?php             surround the php code
   statement;
   statement;
   statement
   ?>
Embedding PHP in web pages

   <?php
   statement;statement;    statement;
               statement;
      statement;statement;
   ?>

                               In general whitespace
                               doesn’t matter
                               Use indenting and
                               separate lines to create
                               readable code
The legendary Hello World program
  <!DOCTYPE HTML PUBLIC "-//W3C/DTD HTML 4.01
     Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
  <html>
  <head>
  <title>This is the first PHP program</title>
  </head>
  <body>
 
 
  <p>
  <?php
  print "Hello World!";
  ?>
  </p>
  </body>
  </html>
The legendary Hello World program
  <!DOCTYPE HTML PUBLIC "-//W3C/DTD HTML 4.01
     Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
  <html>
  <head>
  <title>This is the first PHP program</title>
  </head>
  <body>
 
 
  <p>
  <?php
  print "Hello World!";
  ?>
  </p>
  </body>
  </html>
The legendary Hello World program
  <!DOCTYPE HTML PUBLIC "-//W3C/DTD HTML 4.01
     Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
  <html>
  <head>
  <title>This is the first PHP program</title>
  </head>
  <body>
 
 
  <p>                       print sends a sequence of
  <?php
  print "Hello World!";
                            characters to the output
  ?>
  </p>                      The sequence here is
  </body>                   indicated by start and
  </html>                   end quotes
PHP can be put ‘ nywhere’..
               a
                      All the php blocks are processed
  <html>
  <?php ... ?>
                      before the page is sent
  <head>
  <?php ... ?>
  <title>... <?php ... ?> ...</title>
  </head>
  <body>
 
 
  <p>
  <?php ... ?>
  </p>
  </body>
  </html>
PHP can be put ‘ nywhere’.. but works in sequence
               a

  <html>
  <?php ... ?>               Starting at the top
  <head>
  <?php ... ?>
  <title>... <?php ... ?> ...</title>
  </head>
  <body>
 
 
  <p>
  <?php ... ?>         Working down to the bottom
  </p>
  </body>
  </html>
Statements and semicolons


                     Use ; to separate
   <?php             statements
   statement;
   statement;
   statement;
   ?>
All of these would work the same way...

<?php statement; statement;statement ?>



<?php
statement; statement;statement;
?>



<?php
statement;
statement;
                             This is the best way of
statement;                   laying the code out
?>
Comments
Many different ways to add comments

Comment            Source                 Action
    //                C++              Comments to EOL

    #         Unix shell scripting     Comments to EOL

 /* and */             C             Comments out a block
Comments
  <?php
  php statement; // A comment here
  php statement; # Another comment here

  /* A series of lines
  with comments ignored by the PHP processor
  */
  php statement;
  ?>
Comments
   <?php
   php statement; // A comment here
   php statement; # Another comment here

   /* A series of lines
   with comments ignored by the PHP processor
   */
   php statement;
   ?>




Everything in red is ignored by the PHP interpreter
Language basics

    •   Embedding PHP in Web pages
    •   Whitespace and Line breaks
    •   Statements and semicolons
    •   Comments
    •   Literals / names
    •   Identifiers
    •   Keywords
    •   Data types
Language basics

    •   Embedding PHP in Web pages   ✔
    •   Whitespace and Line breaks   ✔
    •   Statements and semicolons    ✔
    •   Comments                     ✔
    •   Literals / names
    •   Identifiers
    •   Keywords
    •   Data types
Literals

A data value that appears directly in the program

 2001                         An integer
 0xFE                   Hexadecimal number
 1.4142                           Float
 “Hello World”                   String
 ‘Hi’                            String
 true                             Bool
 null                 built in ‘no value’ symbol
Identifiers

Identifiers (or names) in PHP must -

 Begin with an ASCII letter (uppercase or lowercase)

       or begin with the underscore character _

       or any character bet ween ASCII 0x7F to 0xFF



 followed by any of these characters and the digits 0-9
Variables

Variables in PHP are identifiers prefixed by $
    $bill
    $value_count
    $anothervalue3                Valid
    $THIS_IS_NOT_A_GOOD_IDEA
    $_underscore


                                  $not valid
                     Invalid      $[
                                  $3wa
Case sensitivity - names we define are case sensitive



  $value
                         Three different names
  $VALUE
  $vaLUE
Variables

We use variables for items of data that will change
as the program runs

Choose a sensible name and have as many as you
like
                          $total_income
     $bill
                $salary            $month
     $total
                     $percentage_increase
Variables

When we declare a variable, a space is reserved
and labelled for that item (in memory)



     $bill


                                 $bill
Variables

To give it a value, use the equals sign



      $bill


                                    $bill
Variables

To give it a value, use the equals sign



      $bill = 42


                                    $bill
Variables

To give it a value, use the equals sign



      $bill = 42                     42


                                    $bill
Variables

To give it a value, use the equals sign



      $bill


                                    $bill
Variables

To give it a value, use the equals sign



      $bill = 57.98


                                    $bill
Variables

To give it a value, use the equals sign



      $bill = 57.98                57.98


                                    $bill
Variables

To give it a value, use the equals sign



      $bill


                                          $bill
Variables

To give it a value, use the equals sign



      $bill = “No payment”


                                          $bill
Variables

To give it a value, use the equals sign



      $bill = “No payment”         “No payment”


                                          $bill
Variables

If a value is changed, the old value is over written



      $bill


                                   $bill
Variables

If a value is changed, the old value is over written



      $bill = 42;


                                   $bill
Variables

If a value is changed, the old value is over written



      $bill = 42;                   42


                                   $bill
Variables

If a value is changed, the old value is over written



      $bill = 42;                   42
      $bill = 58;
                                   $bill
Variables

If a value is changed, the old value is over written



      $bill = 42;                   58
      $bill = 58;
                                   $bill
Variables

Sometimes we use the old value to recalculate the
new value



     $bill


                                 $bill
Variables

Sometimes we use the old value to recalculate the
new value



     $bill = 42;


                                 $bill
Variables

Sometimes we use the old value to recalculate the
new value



     $bill = 42;                 42


                                 $bill
Variables

Sometimes we use the old value to recalculate the
new value



     $bill = 42;                 42
     $bill = $bill*2 ;
                                 $bill
Variables

Sometimes we use the old value to recalculate the
new value



     $bill = 42;                 84
     $bill = $bill*2 ;
                                 $bill
Variables

Some languages are very strict about what kinds of
data are stored in variables - PHP doesn’t care

 $bill=42;                   Stores an integer

 $bill=42;
 $bill=”Now its a string”;


 print $bull;
Variables

Some languages are very strict about what kinds of
data are stored in variables - PHP doesn’t care

 $bill=42;                   Stores an integer

 $bill=42;                   Over writes with a string
 $bill=”Now its a string”;


 print $bull;
Variables

Some languages are very strict about what kinds of
data are stored in variables - PHP doesn’t care

 $bill=42;                   Stores an integer

 $bill=42;                   Over writes with a string
 $bill=”Now its a string”;

                             Whoops - made a mistake
 print $bull;                   but it still works
Variables

Some languages are very strict about what kinds of
data are stored in variables - PHP doesn’t care

 $bill=42;                   Stores an integer

 $bill=42;                   Over writes with a string
 $bill=”Now its a string”;

                             Whoops - made a mistake
 print $bull;                   but it still works
Keywords
                   _CLASS_ _       Declare        extends           print( )
                   _ _FILE_ _      Default          final            private
Reserved by      _ _FUNCTION_ _     die( )          for            protected
the language       _ _LINE_ _         Do          foreach            public
for core         _ _METHOD_ _       echo( )       function         require( )
                                     Else          global
functionality      Abstract
                      And           elseif           if          require_once( )

                    array( )       empty( )     implements          return( )
                      As          enddeclare     include( )          static
                     Break          endfor     include_once( )      switch

Also - can’t          Case
                     catch
                                  endforeach     interface           tHRow
                                    endif         isset( )
use a built in     cfunction      endswitch        list( )
                                                                      TRy
                                                                    unset( )
function             Class         endwhile         new               use
                     clone
name as a            Const
                                    eval( )     old_function          var
                                  exception          Or
variable            Continue
                                    exit( )    php_user_filter
                                                                     while
                                                                      xor
Data types
PHP provides 8 types

 scalar (single-value)           compound
       integers                    arrays
     floating-point                 objects
        string
       booleans

        Two are special - resource and NULL
Integers
Whole numbers - range depends on the C compiler
that PHP was made in (compiled in)

Typically          +2,147,483,647 to -2,147,483,647



 Octal             0755



 Hexadecimal       0xFF




Larger integers get converted to floats automatically
Floating-Point Numbers

Real numbers - again range is implementation specific

Typically         1.7E-308 to 1.7E+308 with 15
                     digits of accuracy


Examples         3.14, 0.017, -7.1, 0.314E1, 17.0E-3
Strings

Delimited by either single or double quotes

           ‘here is a string’
           “here is another string”
Strings - single quotes

You can use single quotes to enclose double quotes
    $outputstring=‘He then said “Goodbye” and left’;



Useful for easily printing HTML attributes

  $outputstring=‘<a href=”http:/www.bbc.co.uk”>BBC</a>’;
Strings - double quotes

You can use double quotes to enclose single quotes
    $outputstring=”He then said ‘Goodbye’ and left”;
Operators
Standard arithmetic operators: +, -, *, /, % ..

Concatenation operator:      .
     $outputstring=”He then said “.$quote;


Any non-string value is converted to a string before
the concatenation.
Operators

$aBool=true;
$anInt=156;
$aFloat=12.56;
$anotherFloat=12.2E6;
$massiveFloat=12.2E-78;
print "The bool printed looks like this: ".$aBool."<br />";
print "The int printed looks like this: ".$anInt."<br />";
print "The (smaller) float printed looks like this: ".$aFloat."<br />";
print "The larger float printed looks like this: ".$anotherFloat."<br />";
print "The even larger float printed looks like this: ".$massiveFloat."<br />";
Operators

$aBool=true;
$anInt=156;
$aFloat=12.56;
$anotherFloat=12.2E6;
$massiveFloat=12.2E-78;
print "The bool printed looks like this: ".$aBool."<br />";
print "The int printed looks like this: ".$anInt."<br />";
print "The (smaller) float printed looks like this: ".$aFloat."<br />";
print "The larger float printed looks like this: ".$anotherFloat."<br />";
print "The even larger float printed looks like this: ".$massiveFloat."<br />";

More Related Content

What's hot (19)

Ph pbasics
Ph pbasicsPh pbasics
Ph pbasics
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting language
 
php_tizag_tutorial
php_tizag_tutorialphp_tizag_tutorial
php_tizag_tutorial
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Php introduction and configuration
Php introduction and configurationPhp introduction and configuration
Php introduction and configuration
 
Client side scripting
Client side scriptingClient side scripting
Client side scripting
 
php basics
php basicsphp basics
php basics
 
Client side scripting using Javascript
Client side scripting using JavascriptClient side scripting using Javascript
Client side scripting using Javascript
 
Introduction to-php
Introduction to-phpIntroduction to-php
Introduction to-php
 
Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
 
PHP, PHP Developer, Hire PHP Developer, PHP Web Development, Hire PHP Program...
PHP, PHP Developer, Hire PHP Developer, PHP Web Development, Hire PHP Program...PHP, PHP Developer, Hire PHP Developer, PHP Web Development, Hire PHP Program...
PHP, PHP Developer, Hire PHP Developer, PHP Web Development, Hire PHP Program...
 
1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master1336333055 php tutorial_from_beginner_to_master
1336333055 php tutorial_from_beginner_to_master
 
Php
PhpPhp
Php
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
PHP Loops and PHP Forms
PHP  Loops and PHP FormsPHP  Loops and PHP Forms
PHP Loops and PHP Forms
 
Php Basics
Php BasicsPhp Basics
Php Basics
 
Web Application Development using PHP Chapter 1
Web Application Development using PHP Chapter 1Web Application Development using PHP Chapter 1
Web Application Development using PHP Chapter 1
 
vb script
vb scriptvb script
vb script
 

Similar to php app development 1 (20)

Php introduction
Php introductionPhp introduction
Php introduction
 
PHP
PHPPHP
PHP
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
PHP Introduction and Training Material
PHP Introduction and Training MaterialPHP Introduction and Training Material
PHP Introduction and Training Material
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdfWT_PHP_PART1.pdf
WT_PHP_PART1.pdf
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
 
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
 
Lecture8
Lecture8Lecture8
Lecture8
 
LAB PHP Consolidated.ppt
LAB PHP Consolidated.pptLAB PHP Consolidated.ppt
LAB PHP Consolidated.ppt
 
Php unit i
Php unit iPhp unit i
Php unit i
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
Php Tutorial | Introduction Demo | Basics
 Php Tutorial | Introduction Demo | Basics Php Tutorial | Introduction Demo | Basics
Php Tutorial | Introduction Demo | Basics
 
Learning of Php and My SQL Tutorial | For Beginners
Learning of Php and My SQL Tutorial | For BeginnersLearning of Php and My SQL Tutorial | For Beginners
Learning of Php and My SQL Tutorial | For Beginners
 
Php My SQL Tutorial | beginning
Php My SQL Tutorial | beginningPhp My SQL Tutorial | beginning
Php My SQL Tutorial | beginning
 
basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)basic concept of php(Gunikhan sonowal)
basic concept of php(Gunikhan sonowal)
 
php 1
php 1php 1
php 1
 
Php assignment help
Php assignment helpPhp assignment help
Php assignment help
 
Php essentials
Php essentialsPhp essentials
Php essentials
 

Recently uploaded

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 

Recently uploaded (20)

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 

php app development 1

  • 2. Web Scripting using PHP Server side scripting
  • 3. So what is a Server Side Scripting Language? • Programming language code embedded into a web page PERL PHP PYTHON ASP
  • 4. So what is a Server Side Scripting Language? • Programming language code embedded into a web page PERL PHP PYTHON ASP
  • 5. Different ways of scripting the Web • Programming language code embedded into a web page No scripting (plain markup) Client Side scripting Ser ver Side scripting Combination of the above (AJAX)
  • 6. No Scripting example - how it works... User on a machine somewhere Ser ver machine
  • 10. User types in a URL for a page with no programming code inside
  • 11. User types in a URL for a page with no programming code inside Uniform Resource Locator
  • 12. Request is sent to ser ver using HTTP
  • 13. Request is sent to ser ver using HTTP Hypertext Transfer Protocol
  • 14. Ser ver soft ware finds the page
  • 15. Page is sent back, using HTTP
  • 18. User types in a URL for a page with PHP code inside
  • 19. Request is sent to ser ver using HTTP
  • 20. Ser ver soft ware finds the page
  • 21. Ser ver side code is executed
  • 22. Page is sent back, using HTTP
  • 24. Server side scripting languages • Executes in the ser ver • Before the page is sent from server to browser • Ser ver side code is not visible in the client • Ser ver side code can access resources on the server side
  • 25. Browser Web ser ver Database ser ver
  • 26. How many items in stock?
  • 29. Web ser ver executes code Queries database ser ver
  • 34. So why PHP? PERL PHP PYTHON ASP
  • 35. PHP usage ... • Source: PHP programming 2nd Ed.
  • 36. PHP compared to others ... • Source: www.securityspace.com
  • 37. Books - core syntax Programming PHP, Second Edition PHP in a Nutshell By Kevin Tatroe, Rasmus Lerdorf, By Paul Hudson Peter MacIntyre First Edition October 2005 Second Edition April 2006 ** Recommended
  • 38. Books - learning / tutorial based Learning PHP 5 Learning PHP and MySQL By David Sklar By Michele Davis, Jon Phillips First Edition June 2004 First Edition June 2006
  • 39. Other texts.. • There are other publishers / texts (trade books) • Look for books that cover PHP 5 • Open source, server side languages can rapidly develop • Features added or deprecated rapidly
  • 40. PHP development PHP 5 PHP 4 PHP 3 PHP 1 • 5 versions in 10 years
  • 42. Language basics • Embedding PHP in Web pages • Whitespace and Line breaks • Statements and semicolons • Comments • Literals / names • Identifiers • Keywords • Data types
  • 43. Language basics • Embedding PHP in Web pages • Whitespace and Line breaks • Statements and semicolons • Comments • Literals / names • Identifiers • Keywords • Data types Much of this material is explained in PHP programming 2nd Ed. Chap 1 & 2
  • 44. Embedding PHP in web pages Use <?php and ?> to <?php surround the php code statement; statement; statement ?>
  • 45. Embedding PHP in web pages <?php statement;statement; statement; statement; statement;statement; ?> In general whitespace doesn’t matter Use indenting and separate lines to create readable code
  • 46. The legendary Hello World program <!DOCTYPE HTML PUBLIC "-//W3C/DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>This is the first PHP program</title> </head> <body> <p> <?php print "Hello World!"; ?> </p> </body> </html>
  • 47. The legendary Hello World program <!DOCTYPE HTML PUBLIC "-//W3C/DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>This is the first PHP program</title> </head> <body> <p> <?php print "Hello World!"; ?> </p> </body> </html>
  • 48. The legendary Hello World program <!DOCTYPE HTML PUBLIC "-//W3C/DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>This is the first PHP program</title> </head> <body> <p> print sends a sequence of <?php print "Hello World!"; characters to the output ?> </p> The sequence here is </body> indicated by start and </html> end quotes
  • 49. PHP can be put ‘ nywhere’.. a All the php blocks are processed <html> <?php ... ?> before the page is sent <head> <?php ... ?> <title>... <?php ... ?> ...</title> </head> <body> <p> <?php ... ?> </p> </body> </html>
  • 50. PHP can be put ‘ nywhere’.. but works in sequence a <html> <?php ... ?> Starting at the top <head> <?php ... ?> <title>... <?php ... ?> ...</title> </head> <body> <p> <?php ... ?> Working down to the bottom </p> </body> </html>
  • 51. Statements and semicolons Use ; to separate <?php statements statement; statement; statement; ?>
  • 52. All of these would work the same way... <?php statement; statement;statement ?> <?php statement; statement;statement; ?> <?php statement; statement; This is the best way of statement; laying the code out ?>
  • 53. Comments Many different ways to add comments Comment Source Action // C++ Comments to EOL # Unix shell scripting Comments to EOL /* and */ C Comments out a block
  • 54. Comments <?php php statement; // A comment here php statement; # Another comment here /* A series of lines with comments ignored by the PHP processor */ php statement; ?>
  • 55. Comments <?php php statement; // A comment here php statement; # Another comment here /* A series of lines with comments ignored by the PHP processor */ php statement; ?> Everything in red is ignored by the PHP interpreter
  • 56. Language basics • Embedding PHP in Web pages • Whitespace and Line breaks • Statements and semicolons • Comments • Literals / names • Identifiers • Keywords • Data types
  • 57. Language basics • Embedding PHP in Web pages ✔ • Whitespace and Line breaks ✔ • Statements and semicolons ✔ • Comments ✔ • Literals / names • Identifiers • Keywords • Data types
  • 58. Literals A data value that appears directly in the program 2001 An integer 0xFE Hexadecimal number 1.4142 Float “Hello World” String ‘Hi’ String true Bool null built in ‘no value’ symbol
  • 59. Identifiers Identifiers (or names) in PHP must - Begin with an ASCII letter (uppercase or lowercase) or begin with the underscore character _ or any character bet ween ASCII 0x7F to 0xFF followed by any of these characters and the digits 0-9
  • 60. Variables Variables in PHP are identifiers prefixed by $ $bill $value_count $anothervalue3 Valid $THIS_IS_NOT_A_GOOD_IDEA $_underscore $not valid Invalid $[ $3wa
  • 61. Case sensitivity - names we define are case sensitive $value Three different names $VALUE $vaLUE
  • 62. Variables We use variables for items of data that will change as the program runs Choose a sensible name and have as many as you like $total_income $bill $salary $month $total $percentage_increase
  • 63. Variables When we declare a variable, a space is reserved and labelled for that item (in memory) $bill $bill
  • 64. Variables To give it a value, use the equals sign $bill $bill
  • 65. Variables To give it a value, use the equals sign $bill = 42 $bill
  • 66. Variables To give it a value, use the equals sign $bill = 42 42 $bill
  • 67. Variables To give it a value, use the equals sign $bill $bill
  • 68. Variables To give it a value, use the equals sign $bill = 57.98 $bill
  • 69. Variables To give it a value, use the equals sign $bill = 57.98 57.98 $bill
  • 70. Variables To give it a value, use the equals sign $bill $bill
  • 71. Variables To give it a value, use the equals sign $bill = “No payment” $bill
  • 72. Variables To give it a value, use the equals sign $bill = “No payment” “No payment” $bill
  • 73. Variables If a value is changed, the old value is over written $bill $bill
  • 74. Variables If a value is changed, the old value is over written $bill = 42; $bill
  • 75. Variables If a value is changed, the old value is over written $bill = 42; 42 $bill
  • 76. Variables If a value is changed, the old value is over written $bill = 42; 42 $bill = 58; $bill
  • 77. Variables If a value is changed, the old value is over written $bill = 42; 58 $bill = 58; $bill
  • 78. Variables Sometimes we use the old value to recalculate the new value $bill $bill
  • 79. Variables Sometimes we use the old value to recalculate the new value $bill = 42; $bill
  • 80. Variables Sometimes we use the old value to recalculate the new value $bill = 42; 42 $bill
  • 81. Variables Sometimes we use the old value to recalculate the new value $bill = 42; 42 $bill = $bill*2 ; $bill
  • 82. Variables Sometimes we use the old value to recalculate the new value $bill = 42; 84 $bill = $bill*2 ; $bill
  • 83. Variables Some languages are very strict about what kinds of data are stored in variables - PHP doesn’t care $bill=42; Stores an integer $bill=42; $bill=”Now its a string”; print $bull;
  • 84. Variables Some languages are very strict about what kinds of data are stored in variables - PHP doesn’t care $bill=42; Stores an integer $bill=42; Over writes with a string $bill=”Now its a string”; print $bull;
  • 85. Variables Some languages are very strict about what kinds of data are stored in variables - PHP doesn’t care $bill=42; Stores an integer $bill=42; Over writes with a string $bill=”Now its a string”; Whoops - made a mistake print $bull; but it still works
  • 86. Variables Some languages are very strict about what kinds of data are stored in variables - PHP doesn’t care $bill=42; Stores an integer $bill=42; Over writes with a string $bill=”Now its a string”; Whoops - made a mistake print $bull; but it still works
  • 87. Keywords _CLASS_ _ Declare extends print( ) _ _FILE_ _ Default final private Reserved by _ _FUNCTION_ _ die( ) for protected the language _ _LINE_ _ Do foreach public for core _ _METHOD_ _ echo( ) function require( ) Else global functionality Abstract And elseif if require_once( ) array( ) empty( ) implements return( ) As enddeclare include( ) static Break endfor include_once( ) switch Also - can’t Case catch endforeach interface tHRow endif isset( ) use a built in cfunction endswitch list( ) TRy unset( ) function Class endwhile new use clone name as a Const eval( ) old_function var exception Or variable Continue exit( ) php_user_filter while xor
  • 88. Data types PHP provides 8 types scalar (single-value) compound integers arrays floating-point objects string booleans Two are special - resource and NULL
  • 89. Integers Whole numbers - range depends on the C compiler that PHP was made in (compiled in) Typically +2,147,483,647 to -2,147,483,647 Octal 0755 Hexadecimal 0xFF Larger integers get converted to floats automatically
  • 90. Floating-Point Numbers Real numbers - again range is implementation specific Typically 1.7E-308 to 1.7E+308 with 15 digits of accuracy Examples 3.14, 0.017, -7.1, 0.314E1, 17.0E-3
  • 91. Strings Delimited by either single or double quotes ‘here is a string’ “here is another string”
  • 92. Strings - single quotes You can use single quotes to enclose double quotes $outputstring=‘He then said “Goodbye” and left’; Useful for easily printing HTML attributes $outputstring=‘<a href=”http:/www.bbc.co.uk”>BBC</a>’;
  • 93. Strings - double quotes You can use double quotes to enclose single quotes $outputstring=”He then said ‘Goodbye’ and left”;
  • 94. Operators Standard arithmetic operators: +, -, *, /, % .. Concatenation operator: . $outputstring=”He then said “.$quote; Any non-string value is converted to a string before the concatenation.
  • 95. Operators $aBool=true; $anInt=156; $aFloat=12.56; $anotherFloat=12.2E6; $massiveFloat=12.2E-78; print "The bool printed looks like this: ".$aBool."<br />"; print "The int printed looks like this: ".$anInt."<br />"; print "The (smaller) float printed looks like this: ".$aFloat."<br />"; print "The larger float printed looks like this: ".$anotherFloat."<br />"; print "The even larger float printed looks like this: ".$massiveFloat."<br />";
  • 96. Operators $aBool=true; $anInt=156; $aFloat=12.56; $anotherFloat=12.2E6; $massiveFloat=12.2E-78; print "The bool printed looks like this: ".$aBool."<br />"; print "The int printed looks like this: ".$anInt."<br />"; print "The (smaller) float printed looks like this: ".$aFloat."<br />"; print "The larger float printed looks like this: ".$anotherFloat."<br />"; print "The even larger float printed looks like this: ".$massiveFloat."<br />";

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n