Coding In Php

1,415 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,415
On SlideShare
0
From Embeds
0
Number of Embeds
29
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Coding In Php

  1. 1. PHP – Coding in PHP Harit Kothari [email_address]
  2. 2. Agenda <ul><li>PHP HTML Embedding Tags and Syntax </li></ul><ul><li>Simple PHP Script Example </li></ul><ul><li>PHP and HTTP Environment Variables </li></ul>
  3. 3. PHP HTML Embedding Tags and Syntax <ul><li>HTML is written as <tag>content<tag> </li></ul><ul><li>Similarly, PHP Tags can be written as: <?php method; ? > e.g. <?php echo ”Hello World!”; ?> </li></ul><ul><li>So how does it makes sense? - Use different methods to generate contents dynamically - Call PHP functions and get results at runtime </li></ul>
  4. 4. Some other ways to achieve the same <ul><li>SGML Style (we have already seen!) <?php echo ”Hello World!”; ?> </li></ul><ul><li>ASP / JSP Style <% echo “Hello World!”; %> OR (Shortcut) <p><?=”Hello World!”; ?> </li></ul><ul><li>(Java)Script Style <script language = “php”> echo “Hello World!”; </script> </li></ul>
  5. 5. Simple PHP Script Example <ul><li>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> </li></ul>
  6. 6. PHP and HTTP Environment Variables <ul><li>HTTP as a protocol is different, in PHP it has rich set of Global / environment variables. </li></ul><ul><li>They are accessible globally! </li></ul><ul><li>$HTTP_GET_VARS or $_GET </li></ul><ul><li>$HTTP_POST_VARS or $_POST </li></ul><ul><li>$HTTP_COOKIE_VARS or $_COOKIE </li></ul><ul><li>$HTTP_SERVER_VARS or $_SERVER </li></ul><ul><li>$HTTP_ENV_VARS or $_ENV </li></ul><ul><li>$HTTP_POST_FILES </li></ul>
  7. 7. PHP and HTTP Environment Variables - 1 <ul><li>$HTTP_GET_VARS & $HTTP_POST_VARS </li></ul><ul><ul><li>Mostly used in GET and POST requests respectively. </li></ul></ul><ul><ul><li>Contains request information / data. </li></ul></ul><ul><ul><li>Useful in form processing. </li></ul></ul>
  8. 8. PHP and HTTP Environment Variables - 2 <ul><li>$HTTP_COOKIE_VARS </li></ul><ul><ul><li>Cookie is a very small, temporary text file </li></ul></ul><ul><ul><li>A way of session management </li></ul></ul><ul><ul><li>Stored and retrieved user specific information on client </li></ul></ul>
  9. 9. PHP and HTTP Environment Variables - 3 <ul><li>$HTTP_SERVER_VARS </li></ul><ul><ul><li>Various information about server </li></ul></ul><ul><ul><li>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” </li></ul></ul>
  10. 10. PHP and HTTP Environment Variables - 4 <ul><li>$HTTP_ENV_VARS </li></ul><ul><ul><li>Related to accessing machine and OS specific environment variables </li></ul></ul><ul><li>$HTTP_POST_FILES </li></ul><ul><ul><li>Related to file upload </li></ul></ul>
  11. 11. Summary <ul><li>PHP can be written in either of 3 ways, SGML, Script or ASP / JSP styles. </li></ul><ul><li>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. </li></ul>
  12. 12. Whats next? <ul><li>Learning language in dept... </li></ul><ul><ul><li>Variables, Constants and Data Types, and Operators </li></ul></ul><ul><ul><li>Decision Making, Flow Control and Loops </li></ul></ul>

×