PHP HyPertext: Preprocessor

toiletquietInternet και Εφαρμογές Web

5 Δεκ 2013 (πριν από 3 χρόνια και 9 μήνες)

124 εμφανίσεις

PHP

HYPERTEXT
: PREPROCESSOR

By: Justin T.
Pleva

WHAT IS PHP?


General purpose


Server
-
side web development


Console application

BACKGROUND


First created in 1994 by
Rasmus

Lerdorf


Designed to streamline web tasks


Designed to access databases for storing data.


Used for web forms


First public release in 1995



BACKGROUND


Used primarily as website
scripting


Text Interpreter/filter


Installed on over 20 million websites and domains


Can install multiple versions


Current version
5.4


Object
-
Oriented

HISTORY


Originally named “Personal Homepage Tools”


Rewritten in 1997 using C, released publicly


Renamed to “Hypertext Preprocessor”


Version 4 introduced command line functionality


Version 5 rewrote Object support


Version 6 has been postponed

LICENSING


Open source


PHP License


Term “PHP” cannot be used directly in a project.

OPERATING ENVIRONMENTS


Windows


Mac


Linux


Almost any others


Built from source



Web servers


Apache


IIS


Lighttpd

STACKS


Comes bundled with many Linux Distributions


Bundles for


Mac: MAMP (Mac, Apache, MySQL, PHP)


Linux: LAMP (Linux, Apache, MySQL, PHP)


Windows: WAMP …


HOW IT WORKS


Client Request sent to Web server


Web server directs to PHP filter


PHP processes data and sends to web server


Web server sends back to client

SYNTAX


Similar to major programming languages



C


Java



Can be embedded inside other languages such as HTML

SYNTAX
: DECLARATIONS


Declared PHP code with delimiters


<?
php

… ?>


<? … ?>


<script language=”
php
”> </script>


ASP Style


<% … %>



Code is only executed between these delimiters

SYNTAX: VARIABLES


Loosely typed, unlike C/Java


// Create an integer and set equal to 3

$
myVariable

= 3;


Prefixed name with ‘$’


Notice no type specified, this can be a string value of “3”, character ‘3’ or
integer value of 3. Depends upon notation!


Need to be careful with variable types!

SYNTAX: COMMENTING


Similar to other
langues


// This is a single line comment


/* This is a block style comment */

SYNTAX: FUNCTIONS


Functions declarations similar to C/Java


Function
myFunction
($value1, $value2)

{



return $value1 + $value2;

}


Can be value returning or not!

SYNTAX: LOOPS


Similar to C/Java


For … While … Do While … for each


$
i

= 0;

While ( $
i

!= 5 )

{


echo “Number is: “ . $
i

. “<
br

/>;



$
i
++;

}


Notice the ‘.’!

SYNTAX: FILE HANDLING


Can Open and write to file system


Used to read/write from a server for web content


Built in file support for:


XML


FTP


Zip


Cookies

SYNTAX: GET/POST


Can get data using $_Get[“ “]


Useful for retrieving data from
url
.


Can send data using $_Post[“ “]


Useful for submitting user forms such as request information forms.

SYNTAX: OBJECTS


PHP is Object
-
Oriented


Can create classes and objects of any type


Similar to C/Java


Can have private/public methods and data members


Arrow notation instead of dot notation

SYNTAX: MAIL


Built in Email support


Create text based email


Send via 1 function.

FILE EXTENSIONS


Standard extension: .
php


Can have others


.
phtml


.php5


If multiple versions are installed, .php5 will refer to version 5 installed

USAGE


Command line


Dynamic websites


Content Management


Can be used for Desktop applications


GUI controls

DATABASE SUPPORT


Built to work primarily with MySQL


Capable of working with others:


MS SQL


Oracle


Postgres


PDO Driver

SECURITY


Very little security holes have been found with core PHP application


Security risks come from each individual programmer, not the PHP
filter!


Bad programming habits

WEB PRESENCE


20 Million domains/websites


Comes pre installed with many Linux distributions.


Content Management Systems

WEB PRESENCE: CMS


Many Content Management Systems are built with PHP


Joomla


Wordpress


Drupal


Far more built with PHP than others such as
.Net

COMMUNITY SUPPORT


Need help? Google it.


Since PHP is so widely used, there is great community support


Content Management Systems are sometimes community built

SCRIPT AVAILABILITY


Community Support


Open Source


http://www.hotscripts.com


DEVELOPMENT


Code in Notepad


IDE Support


Netbeans


Zend

Studio


Eclipse


Codelobster


CONCLUSION


General Scripting
lanaguage


Over 20 million domains


Command line/Web server
-
side


Various database support


Thousands of pre
-
built scripts


Open source

QUESTIONS?