PHP – Coding in PHP Harit Kothari [email_address]
Agenda PHP HTML Embedding Tags and Syntax Simple PHP Script Example PHP and HTTP Environment Variables
PHP HTML Embedding Tags and Syntax HTML is written as <tag>content<tag> Similarly, PHP Tags can be written as: <?php  method; ? > e.g. <?php echo ”Hello World!”; ?> So how does it makes sense? - Use different methods to generate contents dynamically - Call PHP functions and get results at runtime
Some other ways to achieve the same SGML Style (we have already seen!) <?php echo ”Hello World!”; ?> ASP / JSP Style <% echo “Hello World!”; %> OR (Shortcut) <p><?=”Hello World!”; ?> (Java)Script Style <script language = “php”> echo “Hello World!”; </script>
Simple PHP Script Example A sample program that illustrates different ways to code PHP! <html> <head><title><? Echo “This is a sample PHP page!”; ?></title></head> <body> <h2>A math example</h2> <p>10 + 11 = <%= 10+11 %> <br/>and 8 + 9 = <% echo(8+9); %> </body> </html>
PHP and HTTP Environment Variables HTTP as a protocol is different, in PHP it has rich set of Global / environment variables. They are accessible globally! $HTTP_GET_VARS or $_GET $HTTP_POST_VARS or $_POST $HTTP_COOKIE_VARS or $_COOKIE $HTTP_SERVER_VARS or $_SERVER $HTTP_ENV_VARS or $_ENV $HTTP_POST_FILES
PHP and HTTP Environment Variables - 1 $HTTP_GET_VARS & $HTTP_POST_VARS Mostly used in GET and POST requests respectively. Contains request information / data. Useful in form processing.
PHP and HTTP Environment Variables - 2 $HTTP_COOKIE_VARS Cookie is a very small, temporary text file A way of session management Stored and retrieved user specific information on client
PHP and HTTP Environment Variables - 3 $HTTP_SERVER_VARS Various information about server Examples: SERVER_SOFTWARE “wamp” SERVER_NAME “www.sachinism.com” SERVER_PROTOCOL “HTTP/1.1” SERVER_PORT “80” REQUEST_METHOD “POST” QUERY_STRING “nm=hussu+age=32” REMOTE_HOST “hostname_machine” REMOTE_ADDR “192.168.10.1” AUTH_TYPE “basic” CONTENT_TYPE “x-url-encoded”
PHP and HTTP Environment Variables - 4 $HTTP_ENV_VARS Related to accessing machine and OS specific environment variables $HTTP_POST_FILES Related to file upload
Summary PHP can be written in either of 3 ways, SGML, Script or ASP / JSP styles. PHP environment variables like $_GET, $_POST, $_COOKIE, $_SERVER provides access to data stored in different ways like sent as request, stored as cookies, or some data about server.
Whats next? Learning language in dept... Variables, Constants and Data Types, and Operators Decision Making, Flow Control and Loops

Coding In Php

  • 1.
    PHP – Codingin PHP Harit Kothari [email_address]
  • 2.
    Agenda PHP HTMLEmbedding Tags and Syntax Simple PHP Script Example PHP and HTTP Environment Variables
  • 3.
    PHP HTML EmbeddingTags and Syntax HTML is written as <tag>content<tag> Similarly, PHP Tags can be written as: <?php method; ? > e.g. <?php echo ”Hello World!”; ?> So how does it makes sense? - Use different methods to generate contents dynamically - Call PHP functions and get results at runtime
  • 4.
    Some other waysto achieve the same SGML Style (we have already seen!) <?php echo ”Hello World!”; ?> ASP / JSP Style <% echo “Hello World!”; %> OR (Shortcut) <p><?=”Hello World!”; ?> (Java)Script Style <script language = “php”> echo “Hello World!”; </script>
  • 5.
    Simple PHP ScriptExample A sample program that illustrates different ways to code PHP! <html> <head><title><? Echo “This is a sample PHP page!”; ?></title></head> <body> <h2>A math example</h2> <p>10 + 11 = <%= 10+11 %> <br/>and 8 + 9 = <% echo(8+9); %> </body> </html>
  • 6.
    PHP and HTTPEnvironment Variables HTTP as a protocol is different, in PHP it has rich set of Global / environment variables. They are accessible globally! $HTTP_GET_VARS or $_GET $HTTP_POST_VARS or $_POST $HTTP_COOKIE_VARS or $_COOKIE $HTTP_SERVER_VARS or $_SERVER $HTTP_ENV_VARS or $_ENV $HTTP_POST_FILES
  • 7.
    PHP and HTTPEnvironment Variables - 1 $HTTP_GET_VARS & $HTTP_POST_VARS Mostly used in GET and POST requests respectively. Contains request information / data. Useful in form processing.
  • 8.
    PHP and HTTPEnvironment Variables - 2 $HTTP_COOKIE_VARS Cookie is a very small, temporary text file A way of session management Stored and retrieved user specific information on client
  • 9.
    PHP and HTTPEnvironment Variables - 3 $HTTP_SERVER_VARS Various information about server Examples: SERVER_SOFTWARE “wamp” SERVER_NAME “www.sachinism.com” SERVER_PROTOCOL “HTTP/1.1” SERVER_PORT “80” REQUEST_METHOD “POST” QUERY_STRING “nm=hussu+age=32” REMOTE_HOST “hostname_machine” REMOTE_ADDR “192.168.10.1” AUTH_TYPE “basic” CONTENT_TYPE “x-url-encoded”
  • 10.
    PHP and HTTPEnvironment Variables - 4 $HTTP_ENV_VARS Related to accessing machine and OS specific environment variables $HTTP_POST_FILES Related to file upload
  • 11.
    Summary PHP canbe written in either of 3 ways, SGML, Script or ASP / JSP styles. PHP environment variables like $_GET, $_POST, $_COOKIE, $_SERVER provides access to data stored in different ways like sent as request, stored as cookies, or some data about server.
  • 12.
    Whats next? Learninglanguage in dept... Variables, Constants and Data Types, and Operators Decision Making, Flow Control and Loops