SlideShare a Scribd company logo
1 of 65
Download to read offline
WEB DEVELOPMENT
A workshop on developing a site using PHP
PROJECT
SETUP
Download


https://www.dropbox.com/s/
 kq2r4e403iu566q/vhost.zip
Requirements

๏ Apache2
๏ Php 5.3 or above
๏ MySql
๏ PhpMyAdmin
๏ or MAMP, WAMP, and XAMPP
Steps

๏ Structure of the project
๏ Adding hostname to /etc/hosts
๏ Edit the httpd.conf in Apache
๏ Start Apache and test it
Project Structure

๏ Project Directory
       ๏ web directory
                ๏ index.php
Hosts in MAC/Unix
๏ Mac/Linux in terminal
  sudo vi /etc/hosts



๏ and insert this
  127.0.0.1   www.webcamp.com.local
Hosts in Windows
  Open notepad as a administrator
  Then open the file in
   C:WindowsSystem32driversetchosts

  insert
   127.0.0.1    www.webcamp.com.local

Save the file. Make sure notepad doesn’t append .txt
to the file.
Creating a Virtual Host
๏ MAC
๏   Open /Applications/MAMP/conf/apache/httpd.conf

๏   Change
    Listen 8888 -> Listen 80
    ServerName localhost:8888 -> ServerName localhost

๏   Insert
    NameVirtualHost *:80
    Include /Users/computer_name/Desktop/vhost/*.conf       //sample

๏   Create a new file with an extension .conf and save it to the folder
    /Users/computer_name/Desktop/vhost and insert the code of virtual
    host in this file.
Creating a Virtual Host
๏ WINDOWS
๏ Open C:wampbinapacheApache2.2.11confhttpd.conf
๏ Uncomment Include conf/extra/httpd-vhosts.conf
๏ Open the file in conf/extra/httpd-vhosts.conf
๏ Comment all except for the line NameVirtualHost *:80
๏ Then insert on the last line the code (next page)
Virtual Host
RESTART YOUR APACHE

   and its done!
ACCESSING
DATABASE
Old Way
New Recommended Ways

  ๏ via PDO (PHP Data Objects)
  ๏ via MySQLi
12 database drivers



                               Named &
  API
(OOP)      PDO                 Positional
                              Parameters




        Prepared Statements
Using PDO
Connecting to the Database
Creating a Query using
 Named Parameters
Creating a Query using
Positional Parameters
Preparing a Statement
Executing a Statement with
   Named Parameters
Executing a Statement with
  Positional Parameters
Fetching a Result Set
Error Handling Strategies

     ๏ PDO::ERRMODE_SILENT
     ๏ PDO::ERRMODE_WARNING
     ๏ PDO::ERRMODE_EXCEPTION
Handling Exceptions
Closing Connection
USING $_POST & $_GET
Things to Tackle
1. Request methods of form submission
   • method=”POST”
   • method=”GET”
2. Superglobals
3. $_GET and $_POST
REQUEST
METHODS
Create an HTML Form
GET vs POST

                    GET              POST

 Technical                        Body of HTTP
                    URL
 Difference                         Request


Recommended viewing something       changing
    Usage   without changing it    something
GET vs POST
                           GET                   POST

                ๏ bookmark page        ๏ sensitive information

                ๏ search engines can   ๏ multi-part binary (file
 Advantages                            upload)
                index the page with
                passed data            ๏ large quantities of data


                ๏ size limitation      ๏ can NOT bookmark

Disadvantages   ๏ not for sensitive    ๏ search engine can NOT
                information            index the page
SUPERGLOBALS
Superglobals

accessible

             all scope

available
Superglobals
$GLOBALS
            $_COOKIES
$_SERVER                  $_GET
             $_SESSION
 $_ENV
                          $_POST
            $_REQUEST
 $_FILES
$_GET
represents data sent to the PHP
        script in a URL
$_GET example
$_GET example
$_GET example
$_POST
represents data sent to the PHP
     script via HTTP POST
$_POST example
$_POST example
$_POST example
Hands-on time!
IMAGE
UPLOAD
In 2 steps...

1. File submission (Client)
2. File processing (Server)
To submit a file...
Specify content type
And...
Include a file input
To process a file...

     ๏ Handle
     ๏ Validate
     ๏ Save
Handling the $_FILES
$_FILES
๏ name - original file name

๏ type - file mime type

๏ tmp_name - temporary file location

๏ error - error code

๏ size - file size (in bytes)
Validating

The file must be an image
Validate by...

 ๏ Extension
 ๏ Mime type
 ๏ Attribute
Attribute Validation

  getimagesize( $image )
Saving

move_uploaded_file( $image, $destination )
FORM
VALIDATION
Before validating...

       Sanitize
Sanitize...

Unwanted characters
Validate

Data is acceptable
Sanitize with...

filter_var( $data, $filter )
Using sanitize filters...

๏ FILTER_SANITIZE_EMAIL           ๏ FILTER_SANITIZE_SPECIAL_CHARS
๏ FILTER_SANITIZE_ENCODED         ๏ FILTER_SANITIZE_FULL_SPECIAL_CHARS

๏ FILTER_SANITIZE_MAGIC_QUOTES    ๏ FILTER_SANITIZE_STRING

๏ FILTER_SANITIZE_NUMBER_FLOAT    ๏ FILTER_SANITIZE_STRIPPED

๏ FILTER_SANITIZE_NUMBER_INT      ๏ FILTER_SANITIZE_URL

๏ FILTER_SANITIZE_SPECIAL_CHARS   ๏ FILTER_UNSAFE_RAW
Validate with...

filter_var( $data, $filter )
Using validate filters...
    ๏   FILTER_VALIDATE_BOOLEAN

    ๏   FILTER_VALIDATE_EMAIL

    ๏   FILTER_VALIDATE_FLOAT

    ๏   FILTER_VALIDATE_INT

    ๏   FILTER_VALIDATE_IP

    ๏   FILTER_VALIDATE_REGEXP

    ๏   FILTER_VALIDATE_URL
THANK
 YOU!

More Related Content

What's hot

DBFluteを閉じ込めよう
DBFluteを閉じ込めようDBFluteを閉じ込めよう
DBFluteを閉じ込めようToshio Takiguchi
 
Nette framework (WebElement #28)
Nette framework (WebElement #28)Nette framework (WebElement #28)
Nette framework (WebElement #28)Adam Štipák
 
Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5Yusuke Wada
 
Coders4Africa Talk
Coders4Africa TalkCoders4Africa Talk
Coders4Africa Talknarced133
 
PHP Lecture 4 - Working with form, GET and Post Methods
PHP Lecture 4 - Working with form, GET and Post MethodsPHP Lecture 4 - Working with form, GET and Post Methods
PHP Lecture 4 - Working with form, GET and Post MethodsAl-Mamun Sarkar
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applicationselliando dias
 
Introduzione JQuery
Introduzione JQueryIntroduzione JQuery
Introduzione JQueryorestJump
 
PHP Lecture 6 - Php file uploading
PHP Lecture 6 - Php file uploadingPHP Lecture 6 - Php file uploading
PHP Lecture 6 - Php file uploadingAl-Mamun Sarkar
 
Database Management - Lecture 4 - PHP and Mysql
Database Management - Lecture 4 - PHP and MysqlDatabase Management - Lecture 4 - PHP and Mysql
Database Management - Lecture 4 - PHP and MysqlAl-Mamun Sarkar
 
Undercover Pods / WP Functions
Undercover Pods / WP FunctionsUndercover Pods / WP Functions
Undercover Pods / WP Functionspodsframework
 
Introduction to the Pods JSON API
Introduction to the Pods JSON APIIntroduction to the Pods JSON API
Introduction to the Pods JSON APIpodsframework
 
An Introduction to Symfony
An Introduction to SymfonyAn Introduction to Symfony
An Introduction to Symfonyxopn
 
Angular.js Fundamentals
Angular.js FundamentalsAngular.js Fundamentals
Angular.js FundamentalsMark
 
HTML Templates Using Clear Silver
HTML Templates Using Clear SilverHTML Templates Using Clear Silver
HTML Templates Using Clear SilverPaulWay
 

What's hot (20)

DBFluteを閉じ込めよう
DBFluteを閉じ込めようDBFluteを閉じ込めよう
DBFluteを閉じ込めよう
 
Nette framework (WebElement #28)
Nette framework (WebElement #28)Nette framework (WebElement #28)
Nette framework (WebElement #28)
 
Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5
 
Coders4Africa Talk
Coders4Africa TalkCoders4Africa Talk
Coders4Africa Talk
 
Assetic (Zendcon)
Assetic (Zendcon)Assetic (Zendcon)
Assetic (Zendcon)
 
PHP Lecture 4 - Working with form, GET and Post Methods
PHP Lecture 4 - Working with form, GET and Post MethodsPHP Lecture 4 - Working with form, GET and Post Methods
PHP Lecture 4 - Working with form, GET and Post Methods
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
 
Introduzione JQuery
Introduzione JQueryIntroduzione JQuery
Introduzione JQuery
 
Javascript
JavascriptJavascript
Javascript
 
PHP Lecture 6 - Php file uploading
PHP Lecture 6 - Php file uploadingPHP Lecture 6 - Php file uploading
PHP Lecture 6 - Php file uploading
 
Database Management - Lecture 4 - PHP and Mysql
Database Management - Lecture 4 - PHP and MysqlDatabase Management - Lecture 4 - PHP and Mysql
Database Management - Lecture 4 - PHP and Mysql
 
Perl5i
Perl5iPerl5i
Perl5i
 
Undercover Pods / WP Functions
Undercover Pods / WP FunctionsUndercover Pods / WP Functions
Undercover Pods / WP Functions
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
Php talk
Php talkPhp talk
Php talk
 
Introduction to the Pods JSON API
Introduction to the Pods JSON APIIntroduction to the Pods JSON API
Introduction to the Pods JSON API
 
An Introduction to Symfony
An Introduction to SymfonyAn Introduction to Symfony
An Introduction to Symfony
 
Angular.js Fundamentals
Angular.js FundamentalsAngular.js Fundamentals
Angular.js Fundamentals
 
HTML Templates Using Clear Silver
HTML Templates Using Clear SilverHTML Templates Using Clear Silver
HTML Templates Using Clear Silver
 
Nanoc
NanocNanoc
Nanoc
 

Similar to PHP Web Development

Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!Jeff Jones
 
Web scraping 101 with goutte
Web scraping 101 with goutteWeb scraping 101 with goutte
Web scraping 101 with goutteJoshua Copeland
 
Mastering WordPress Vol.1
Mastering WordPress Vol.1Mastering WordPress Vol.1
Mastering WordPress Vol.1Wataru OKAMOTO
 
Php on the Web and Desktop
Php on the Web and DesktopPhp on the Web and Desktop
Php on the Web and DesktopElizabeth Smith
 
Deploying
DeployingDeploying
Deployingsoon
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207patter
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to TornadoGavin Roy
 
Into The Box 2018 Going live with commandbox and docker
Into The Box 2018 Going live with commandbox and dockerInto The Box 2018 Going live with commandbox and docker
Into The Box 2018 Going live with commandbox and dockerOrtus Solutions, Corp
 
Going live with BommandBox and docker Into The Box 2018
Going live with BommandBox and docker Into The Box 2018Going live with BommandBox and docker Into The Box 2018
Going live with BommandBox and docker Into The Box 2018Ortus Solutions, Corp
 
Learning To Run - XPages for Lotus Notes Client Developers
Learning To Run - XPages for Lotus Notes Client DevelopersLearning To Run - XPages for Lotus Notes Client Developers
Learning To Run - XPages for Lotus Notes Client DevelopersKathy Brown
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsAdrien Guéret
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkBo-Yi Wu
 
HTTP Caching and PHP
HTTP Caching and PHPHTTP Caching and PHP
HTTP Caching and PHPDavid de Boer
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
Learning to run
Learning to runLearning to run
Learning to rundominion
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsMichael Peacock
 
Embracing HTTP in the era of API’s
Embracing HTTP in the era of API’sEmbracing HTTP in the era of API’s
Embracing HTTP in the era of API’sVisug
 
The Django Web Application Framework
The Django Web Application FrameworkThe Django Web Application Framework
The Django Web Application FrameworkSimon Willison
 

Similar to PHP Web Development (20)

Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!
 
Web scraping 101 with goutte
Web scraping 101 with goutteWeb scraping 101 with goutte
Web scraping 101 with goutte
 
Mastering WordPress Vol.1
Mastering WordPress Vol.1Mastering WordPress Vol.1
Mastering WordPress Vol.1
 
Php on the Web and Desktop
Php on the Web and DesktopPhp on the Web and Desktop
Php on the Web and Desktop
 
Deploying
DeployingDeploying
Deploying
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
 
Into The Box 2018 Going live with commandbox and docker
Into The Box 2018 Going live with commandbox and dockerInto The Box 2018 Going live with commandbox and docker
Into The Box 2018 Going live with commandbox and docker
 
Going live with BommandBox and docker Into The Box 2018
Going live with BommandBox and docker Into The Box 2018Going live with BommandBox and docker Into The Box 2018
Going live with BommandBox and docker Into The Box 2018
 
Learning To Run - XPages for Lotus Notes Client Developers
Learning To Run - XPages for Lotus Notes Client DevelopersLearning To Run - XPages for Lotus Notes Client Developers
Learning To Run - XPages for Lotus Notes Client Developers
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Sprockets
SprocketsSprockets
Sprockets
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
Copy of cgi
Copy of cgiCopy of cgi
Copy of cgi
 
HTTP Caching and PHP
HTTP Caching and PHPHTTP Caching and PHP
HTTP Caching and PHP
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Learning to run
Learning to runLearning to run
Learning to run
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
 
Embracing HTTP in the era of API’s
Embracing HTTP in the era of API’sEmbracing HTTP in the era of API’s
Embracing HTTP in the era of API’s
 
The Django Web Application Framework
The Django Web Application FrameworkThe Django Web Application Framework
The Django Web Application Framework
 

PHP Web Development