0% found this document useful (0 votes)
7 views35 pages

Webdev Week 5 1

Uploaded by

sanguesamara85
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views35 pages

Webdev Week 5 1

Uploaded by

sanguesamara85
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

WEB

APPLICATION
DEVELOPMENT
// WEEK 5-6
PHP Functions
PHP Functions
● PHP has more than 1000 built-in functions, and in addition
you can create your own custom functions.
● Besides the built-in PHP functions, here’s a way to create
your own functions:

➢ A function is a block of statements that can be used


repeatedly in a program.
➢ A function will not execute automatically when a page
loads.
➢ A function will be executed by a call to the function.

PHP BUILT IN FUNCTIONS OVERVIEW


PHP Functions Arguments

Arguments are specified after the


function name, inside the
parentheses. You can add as many
arguments as you want, just separate
them with a comma.
TWO ARGUMENTS EXAMPLE
PHP Default
Argument Value
Passing Arguments by
Reference
Variable Number of
Arguments
PHP Return Type
Declarations
SUPERGLOBALS
PHP $GLOBALS
● $GLOBALS is an array that contains all global
variables.

● Global variables are variables that can be accessed


from any scope.
CREATING GLOBAL VARIABLE
$SERVER
PHP $SERVER

$_SERVER is a PHP super global


variable which holds information
about headers, paths, and script
locations.
Element/Code Description
$_SERVER['PHP_SELF'] Returns the filename of the currently executing script
$_SERVER['GATEWAY_INT Returns the version of the Common Gateway Interface
ERFACE'] (CGI) the server is using
$_SERVER['SERVER_ADDR Returns the IP address of the host server
']
$_SERVER['SERVER_NAME Returns the name of the host server
']
$_SERVER['SERVER_SOFT Returns the server identification string (such as
WARE'] Apache/2.2.24)
$_SERVER['SERVER_PROT Returns the name and revision of the information protocol
OCOL'] (such as HTTP/1.1)
$_SERVER['REQUEST_MET Returns the request method used to access the page
HOD'] (such as POST)
$_SERVER['REQUEST_TIM Returns the timestamp of the start of the request (such
E'] as 1377687496)
$_SERVER['QUERY_STRIN Returns the query string if the page is accessed via a
G'] query string
$_SERVER['HTTP_ACCEPT' Returns the Accept header from the current request
]
Element/Code Description
$_SERVER['HTTP_ACCEPT Returns the Accept_Charset header from the current
_CHARSET'] request (such as utf-8,ISO-8859-1)
$_SERVER['HTTP_HOST'] Returns the Host header from the current request
$_SERVER['HTTP_REFERE Returns the complete URL of the current page (not
R'] reliable because not all user-agents support it)
$_SERVER['HTTPS'] Is the script queried through a secure HTTP protocol
$_SERVER['REMOTE_ADDR Returns the IP address from where the user is viewing
'] the current page
$_SERVER['REMOTE_HOST Returns the Host name from where the user is viewing
'] the current page
$_SERVER['REMOTE_PORT Returns the port being used on the user's machine to
'] communicate with the web server
$_SERVER['SCRIPT_FILEN Returns the absolute pathname of the currently executing
AME'] script
$_SERVER['SERVER_ADMI Returns the value given to the SERVER_ADMIN
N'] directive in the web server configuration file (if your script
runs on a virtual host, it will be the value defined for that
virtual host)
$_SERVER['SERVER_PORT' Returns the port on the server machine being used by
] the web server for communication (such as 80)
Element/Code Description
$_SERVER['SERVER_SIGN Returns the server version and virtual host name which
ATURE'] are added to server-generated pages
$_SERVER['PATH_TRANSL Returns the file system based path to the current script
ATED']
$_SERVER['SCRIPT_NAME'] Returns the path of the current script
$_SERVER['SCRIPT_URI'] Returns the URI of the current page
$REQUEST
PHP $REQUEST

$_REQUEST is a PHP super global


variable which contains
submitted form data, and all
cookie data.
$POST
PHP $POST
● $_POST contains an array of variables
received via the HTTP POST method.

● There are two main ways to send


variables via the HTTP Post method:
○ HTML forms
○ JavaScript HTTP requests
$_POST in JavaScript HTTP
Requests
$GET
PHP $GET
● $_GET contains an array of variables
received via the HTTP GET method.

● There are two main ways to send


variables via the HTTP GET method:
○ Query strings in the URL
○ HTML Forms
WEEK 5 // ENDS

You might also like