php mysql training : module 3

12
PHP – Module 3 Hussain Fakhruddin [email protected]

Upload: hussulinux

Post on 24-May-2015

6.017 views

Category:

Technology


4 download

DESCRIPTION

PHP HTML Embedding Tags and Syntax Simple PHP Script Example PHP and HTTP Environment Variables

TRANSCRIPT

Page 1: PHP MySQL Training : Module 3

PHP – Module 3

Hussain [email protected]

Page 2: PHP MySQL Training : Module 3

Agenda

● PHP HTML Embedding Tags and Syntax● Simple PHP Script Example● PHP and HTTP Environment Variables

Page 3: PHP MySQL Training : Module 3

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 run-time

Page 4: PHP MySQL Training : Module 3

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>

Page 5: PHP MySQL Training : Module 3

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>

Page 6: PHP MySQL Training : Module 3

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

Page 7: PHP MySQL Training : Module 3

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.

Page 8: PHP MySQL Training : Module 3

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

Page 9: PHP MySQL Training : Module 3

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”

Page 10: PHP MySQL Training : Module 3

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

Page 11: PHP MySQL Training : Module 3

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.

Page 12: PHP MySQL Training : Module 3

Whats next?

● Learning language in dept...● Variables, Constants and Data Types, and Op-

erators● Decision Making, Flow Control and Loops