Your SlideShare is downloading. ×
0
WEB DEVELOPMENTA workshop on developing a site using PHP
PROJECTSETUP
Downloadhttps://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...
Creating a Virtual Host๏ MAC๏   Open /Applications/MAMP/conf/apache/httpd.conf๏   Change    Listen 8888 -> Listen 80    Se...
Creating a Virtual Host๏ WINDOWS๏ Open C:wampbinapacheApache2.2.11confhttpd.conf๏ Uncomment Include conf/extra/httpd-vhost...
Virtual Host
RESTART YOUR APACHE   and its done!
ACCESSINGDATABASE
Old Way
New Recommended Ways  ๏ via PDO (PHP Data Objects)  ๏ via MySQLi
12 database drivers                               Named &  API(OOP)      PDO                 Positional                   ...
Using PDO
Connecting to the Database
Creating a Query using Named Parameters
Creating a Query usingPositional 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 Tackle1. Request methods of form submission   • method=”POST”   • method=”GET”2. Superglobals3. $_GET and $_POST
REQUESTMETHODS
Create an HTML Form
GET vs POST                    GET              POST Technical                        Body of HTTP                    URL ...
GET vs POST                           GET                   POST                ๏ bookmark page        ๏ sensitive informa...
SUPERGLOBALS
Superglobalsaccessible             all scopeavailable
Superglobals$GLOBALS            $_COOKIES$_SERVER                  $_GET             $_SESSION $_ENV                      ...
$_GETrepresents data sent to the PHP        script in a URL
$_GET example
$_GET example
$_GET example
$_POSTrepresents data sent to the PHP     script via HTTP POST
$_POST example
$_POST example
$_POST example
Hands-on time!
IMAGEUPLOAD
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...
ValidatingThe file must be an image
Validate by... ๏ Extension ๏ Mime type ๏ Attribute
Attribute Validation  getimagesize( $image )
Savingmove_uploaded_file( $image, $destination )
FORMVALIDATION
Before validating...       Sanitize
Sanitize...Unwanted characters
ValidateData is acceptable
Sanitize with...filter_var( $data, $filter )
Using sanitize filters...๏ FILTER_SANITIZE_EMAIL           ๏ FILTER_SANITIZE_SPECIAL_CHARS๏ FILTER_SANITIZE_ENCODED        ...
Validate with...filter_var( $data, $filter )
Using validate filters...    ๏   FILTER_VALIDATE_BOOLEAN    ๏   FILTER_VALIDATE_EMAIL    ๏   FILTER_VALIDATE_FLOAT    ๏   F...
THANK YOU!
Upcoming SlideShare
Loading in...5
×

PHP Web Development

646

Published on

2 Comments
0 Likes
Statistics
Notes
  • Be the first to like this

No Downloads
Views
Total Views
646
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
44
Comments
2
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "PHP Web Development"

  1. 1. WEB DEVELOPMENTA workshop on developing a site using PHP
  2. 2. PROJECTSETUP
  3. 3. Downloadhttps://www.dropbox.com/s/ kq2r4e403iu566q/vhost.zip
  4. 4. Requirements๏ Apache2๏ Php 5.3 or above๏ MySql๏ PhpMyAdmin๏ or MAMP, WAMP, and XAMPP
  5. 5. Steps๏ Structure of the project๏ Adding hostname to /etc/hosts๏ Edit the httpd.conf in Apache๏ Start Apache and test it
  6. 6. Project Structure๏ Project Directory ๏ web directory ๏ index.php
  7. 7. Hosts in MAC/Unix๏ Mac/Linux in terminal sudo vi /etc/hosts๏ and insert this 127.0.0.1 www.webcamp.com.local
  8. 8. Hosts in Windows Open notepad as a administrator Then open the file in C:WindowsSystem32driversetchosts insert 127.0.0.1 www.webcamp.com.localSave the file. Make sure notepad doesn’t append .txtto the file.
  9. 9. 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.
  10. 10. 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)
  11. 11. Virtual Host
  12. 12. RESTART YOUR APACHE and its done!
  13. 13. ACCESSINGDATABASE
  14. 14. Old Way
  15. 15. New Recommended Ways ๏ via PDO (PHP Data Objects) ๏ via MySQLi
  16. 16. 12 database drivers Named & API(OOP) PDO Positional Parameters Prepared Statements
  17. 17. Using PDO
  18. 18. Connecting to the Database
  19. 19. Creating a Query using Named Parameters
  20. 20. Creating a Query usingPositional Parameters
  21. 21. Preparing a Statement
  22. 22. Executing a Statement with Named Parameters
  23. 23. Executing a Statement with Positional Parameters
  24. 24. Fetching a Result Set
  25. 25. Error Handling Strategies ๏ PDO::ERRMODE_SILENT ๏ PDO::ERRMODE_WARNING ๏ PDO::ERRMODE_EXCEPTION
  26. 26. Handling Exceptions
  27. 27. Closing Connection
  28. 28. USING $_POST & $_GET
  29. 29. Things to Tackle1. Request methods of form submission • method=”POST” • method=”GET”2. Superglobals3. $_GET and $_POST
  30. 30. REQUESTMETHODS
  31. 31. Create an HTML Form
  32. 32. GET vs POST GET POST Technical Body of HTTP URL Difference RequestRecommended viewing something changing Usage without changing it something
  33. 33. 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 bookmarkDisadvantages ๏ not for sensitive ๏ search engine can NOT information index the page
  34. 34. SUPERGLOBALS
  35. 35. Superglobalsaccessible all scopeavailable
  36. 36. Superglobals$GLOBALS $_COOKIES$_SERVER $_GET $_SESSION $_ENV $_POST $_REQUEST $_FILES
  37. 37. $_GETrepresents data sent to the PHP script in a URL
  38. 38. $_GET example
  39. 39. $_GET example
  40. 40. $_GET example
  41. 41. $_POSTrepresents data sent to the PHP script via HTTP POST
  42. 42. $_POST example
  43. 43. $_POST example
  44. 44. $_POST example
  45. 45. Hands-on time!
  46. 46. IMAGEUPLOAD
  47. 47. In 2 steps...1. File submission (Client)2. File processing (Server)
  48. 48. To submit a file...Specify content type
  49. 49. And...Include a file input
  50. 50. To process a file... ๏ Handle ๏ Validate ๏ Save
  51. 51. Handling the $_FILES
  52. 52. $_FILES๏ name - original file name๏ type - file mime type๏ tmp_name - temporary file location๏ error - error code๏ size - file size (in bytes)
  53. 53. ValidatingThe file must be an image
  54. 54. Validate by... ๏ Extension ๏ Mime type ๏ Attribute
  55. 55. Attribute Validation getimagesize( $image )
  56. 56. Savingmove_uploaded_file( $image, $destination )
  57. 57. FORMVALIDATION
  58. 58. Before validating... Sanitize
  59. 59. Sanitize...Unwanted characters
  60. 60. ValidateData is acceptable
  61. 61. Sanitize with...filter_var( $data, $filter )
  62. 62. 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
  63. 63. Validate with...filter_var( $data, $filter )
  64. 64. Using validate filters... ๏ FILTER_VALIDATE_BOOLEAN ๏ FILTER_VALIDATE_EMAIL ๏ FILTER_VALIDATE_FLOAT ๏ FILTER_VALIDATE_INT ๏ FILTER_VALIDATE_IP ๏ FILTER_VALIDATE_REGEXP ๏ FILTER_VALIDATE_URL
  65. 65. THANK YOU!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×