SlideShare a Scribd company logo
1 of 85
Download to read offline
PHP
modern
not your grandma’s php
& secure
Who is this guy?
Ben Edmunds	

!
@benedmunds	

http://benedmunds.com
Who is this guy?
Ben Edmunds	

!
Open Source 	

Author	

PHP Town Hall Podcast	

CTO at Mindfulware
Welcome to
the Future
Welcome to the Future
Exceptions
Namespaces
Closures
Welcome to the Future
Statics
PDO
Short Arrays
Security
Legit Tools
Legit Tools
Built-in Server
Unit Testing
Composer
Welcome to!
the Future
Great Scott!
Exceptions
Exceptions
try {

	 	 //your code goes here

}

catch (Exception $e) {

	 	 die($e->getMessage());

}
Exceptions
try {

	 	 //your code goes here

}

catch (Exception $e) {

	 	 die($e->getMessage());

}
Closures
Closures
Route::get(‘/', function(){

	 

return View::make(‘index');

!
});
Closures
Route::get(‘/', function(){

	 

return View::make(‘index');

!
});
Namespaces
Namespaces
namespace IlluminateConsole;

class Command

{

	 //…
Namespaces
use IlluminateConsoleCommand;
namespace IlluminateConsole;

class Command

{

	 //…
Namespaces
use IlluminateConsoleCommand;
namespace IlluminateConsole;

class Command

{

	 //…
Statics
Statics
Class Route {

	 public static function get() {

	 	 //… 

	 }
Statics
Route::get();
Class Route {

	 public static function get() {

	 	 //… 

	 }
Statics
Route::get();
Class Route {

	 public static function get() {

	 	 //… 

	 }
Statics
	 	 NO $this

	 

	 	 $var = self::varAtDefinition;

!
	 	 $var = static::varAtExec;
Short Array!
Syntax
Short Array Syntax
$array = array(

	 0 => ‘value1’,

	 1 => ‘value2’,

);
Short Array Syntax
$array = [

	 0 => ‘value1’,

	 1 => ‘value2’,

];
Short Array Syntax
$array = [

	 0 => ‘value1’,

	 1 => ‘value2’,

];
PDO
PDO
Cross System
PDO
Cross System
MS SQL

MySQL

Oracle

PostgreSQL

SQLite
CUBRID

Firebird

Informix

ODBC & DB2

4D
PDO
Cross System
Safe Binding
PDO
$stmt = $db->prepare(‘

	 SELECT * FROM users

	 WHERE id=:id

’);

!
$stmt->bindParam(‘:id’, $id);

$stmt->execute();
Security
Security
SQL Injection
HTTPS
Password Hashing
Security
Authentication
Safe Defaults
XSS & CSRF
Security
//escaping input

$stmt->bindParam(‘:id’, $id);
Security
//escaping input

$stmt->bindParam(‘:id’, $id);
//escaping output

htmlentities($_POST[‘name’]);
Security
HTTPS / SSL

!
Encrypts traffic across the wire

!
Trusted sender and receiver

!
Required by OAUTH 2
Security
//authentication - access control

if (!$user->inGroup(‘admin’)) {

	 return ‘ERROR YO’;

}
Security
//authentication - brute force

if ($user->loginAttempts > 5) {

	 return ‘CAUGHT YA’;

}
Security
//safe password hashing

password_hash($_POST['pass']);
Security
//safe password hashing

password_hash($_POST['pass']);
//password verification

password_verify($_POST['pass'], $u->pass);
Security
//safe defaults

class Your Controller {

	 protected $var1 = ‘default value’;

!
	 function __construct() { … }

}
Security
//safe defaults

$something = false;

!
foreach ($array as $k => $v) {

	 $something = $v->foo;

	 if ($something == ‘bar’) { … }

}
Security
//Non-Persistent XSS

!
http://www.yourSite.com/

?page_num=2&per_page=50

!
Send the link to someone, boom
Security
//Persistent XSS

!
Same idea, except with data that is
saved to the server and 

re-displayed
Security
//XSS Protection

!
<h1>Title</h1>

Hello <?=htmlentities($name)?>

!
!
Security
//Cross Site Request Forgery

//(CSRF)

!
http://yourSite.com/

users/12/delete

!
!
Security
//CSRF Protection

!
POST / PUT / UPDATE / DELETE

behind forms with one-time use
tokens

!
!
Security
//CSRF Protection

!
function generateCsrf() {

$token = mcrypt_create_iv(

16, MCRYPT_DEV_URANDOM);

Session::flash('csrfToken', $token);

return $token; 

}
Security
//CSRF Protection

!
if (

$_POST['token'] == Session::get(‘csrfToken')

) { … }
!
Legit Tools
Built-in !
Web Server
Built-in Server
$ php -S localhost:8000

!
PHP 5.4.0 Development Server started…
Listening on localhost:8000

Document root is /home/ben/htdocs

Press Ctrl-C to quit
Composer
Another
Package Manager!?
Composer
Sane Package

Management
Composer
Autoloading
Composer
PEAR, ha!
packagist.org
Composer
/ composer.json

!
{

	 "require": {

	 	 "stripe/stripe-php": "dev-master",

"twilio/sdk": "dev-master"

	 }

}
Composer
$ php composer.phar update
$ php composer.phar install
Composer
$client = 

new Services_Twilio($sid, $tkn);
!
$client->account

->messages

->sendMessage(…)
Unit Testing
Unit Testing
PHPUnit

Behat

Mink
Selenium

CodeCeption

PHPSpec
Unit Testing
class ApiAuthTest extends PHPUnit_Framework_TestCase {

!
public function testVerify() {

!
	 $auth = new apiAuth();

	 	 

	 $this->assertTrue($auth->verify());
Unit Testing
class ApiAuthTest extends PHPUnit_Framework_TestCase {

!
public function testVerify() {

!
	 $auth = new apiAuth();

	 	 

	 $this->assertTrue($auth->verify());
Unit Testing
$ phpunit tests

!
PHPUnit 3.3.17 by Sebastian Bergmann.

Time: 0.01 seconds

OK (1 tests, 1 assertions)
Resources
Resources
PHP.net
Resources
Modern Frameworks
Laravel

Symfony2

Fuel PHP
SlimPHP 2

Aura for PHP

Silex
Resources
leanpub.com/

phptherightway
PHPtheRightWay.com
Resources
BuildSecurePHPapps.com
Coupon Code:

codementor
$3 off
http://buildsecurephpapps.com/?coupon=codementor
Q/A TIME!
Ben Edmunds	

@benedmunds	

http://benedmunds.com
http://buildsecurephpapps.com/?coupon=codementor

More Related Content

What's hot

Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
diego_k
 
Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)
Kris Wallsmith
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web framework
taggg
 

What's hot (20)

Webrtc mojo
Webrtc mojoWebrtc mojo
Webrtc mojo
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
Inside Bokete: Web Application with Mojolicious and others
Inside Bokete:  Web Application with Mojolicious and othersInside Bokete:  Web Application with Mojolicious and others
Inside Bokete: Web Application with Mojolicious and others
 
Mojo as a_client
Mojo as a_clientMojo as a_client
Mojo as a_client
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony Techniques
 
Building Cloud Castles
Building Cloud CastlesBuilding Cloud Castles
Building Cloud Castles
 
Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers Steal
 
With a Mighty Hammer
With a Mighty HammerWith a Mighty Hammer
With a Mighty Hammer
 
Building Cloud Castles - LRUG
Building Cloud Castles - LRUGBuilding Cloud Castles - LRUG
Building Cloud Castles - LRUG
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101
 
Hello World on Slim Framework 3.x
Hello World on Slim Framework 3.xHello World on Slim Framework 3.x
Hello World on Slim Framework 3.x
 
Mojolicious: what works and what doesn't
Mojolicious: what works and what doesn'tMojolicious: what works and what doesn't
Mojolicious: what works and what doesn't
 
Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)
 
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupScaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hope
 
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
 
Mojolicious on Steroids
Mojolicious on SteroidsMojolicious on Steroids
Mojolicious on Steroids
 
Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web framework
 

Viewers also liked

Creating a Simple PHP and MySQL-Based Login System
Creating a Simple PHP and MySQL-Based Login SystemCreating a Simple PHP and MySQL-Based Login System
Creating a Simple PHP and MySQL-Based Login System
Azharul Haque Shohan
 

Viewers also liked (8)

Magento 2 Workflows
Magento 2 WorkflowsMagento 2 Workflows
Magento 2 Workflows
 
11 tools for your PHP devops stack
11 tools for your PHP devops stack11 tools for your PHP devops stack
11 tools for your PHP devops stack
 
OSGi IoT Demo & Contest 2015
OSGi IoT Demo & Contest 2015OSGi IoT Demo & Contest 2015
OSGi IoT Demo & Contest 2015
 
Rest api design by george reese
Rest api design by george reeseRest api design by george reese
Rest api design by george reese
 
Modern PHP
Modern PHPModern PHP
Modern PHP
 
Creating a Simple PHP and MySQL-Based Login System
Creating a Simple PHP and MySQL-Based Login SystemCreating a Simple PHP and MySQL-Based Login System
Creating a Simple PHP and MySQL-Based Login System
 
25 php interview questions – codementor
25 php interview questions – codementor25 php interview questions – codementor
25 php interview questions – codementor
 
26 Disruptive & Technology Trends 2016 - 2018
26 Disruptive & Technology Trends 2016 - 201826 Disruptive & Technology Trends 2016 - 2018
26 Disruptive & Technology Trends 2016 - 2018
 

Similar to Building Modern and Secure PHP Applications – Codementor Office Hours with Ben Edmunds

Php Security3895
Php Security3895Php Security3895
Php Security3895
Aung Khant
 
Security Bootcamp 2013 lap trinh web an toan
Security Bootcamp 2013   lap trinh web an toanSecurity Bootcamp 2013   lap trinh web an toan
Security Bootcamp 2013 lap trinh web an toan
Security Bootcamp
 
Security Bootcamp 2013 - Lap trinh web an toan
Security Bootcamp 2013 - Lap trinh web an toanSecurity Bootcamp 2013 - Lap trinh web an toan
Security Bootcamp 2013 - Lap trinh web an toan
Security Bootcamp
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 

Similar to Building Modern and Secure PHP Applications – Codementor Office Hours with Ben Edmunds (20)

Php Security
Php SecurityPhp Security
Php Security
 
Php Security By Mugdha And Anish
Php Security By Mugdha And AnishPhp Security By Mugdha And Anish
Php Security By Mugdha And Anish
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
Php security3895
Php security3895Php security3895
Php security3895
 
PHP Security
PHP SecurityPHP Security
PHP Security
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
Web 8 | Introduction to PHP
Web 8 | Introduction to PHPWeb 8 | Introduction to PHP
Web 8 | Introduction to PHP
 
Php Security3895
Php Security3895Php Security3895
Php Security3895
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
Service intergration
Service intergration Service intergration
Service intergration
 
Security Bootcamp 2013 lap trinh web an toan
Security Bootcamp 2013   lap trinh web an toanSecurity Bootcamp 2013   lap trinh web an toan
Security Bootcamp 2013 lap trinh web an toan
 
Security Bootcamp 2013 - Lap trinh web an toan
Security Bootcamp 2013 - Lap trinh web an toanSecurity Bootcamp 2013 - Lap trinh web an toan
Security Bootcamp 2013 - Lap trinh web an toan
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
PHP code examples
PHP code examplesPHP code examples
PHP code examples
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 

More from Arc & Codementor

Angular meteor for angular devs
Angular meteor for angular devsAngular meteor for angular devs
Angular meteor for angular devs
Arc & Codementor
 

More from Arc & Codementor (13)

Remote Career Summit 2020 - the State of Remote Jobs - Weiting Liu of Arc
Remote Career Summit 2020 - the State of Remote Jobs - Weiting Liu of ArcRemote Career Summit 2020 - the State of Remote Jobs - Weiting Liu of Arc
Remote Career Summit 2020 - the State of Remote Jobs - Weiting Liu of Arc
 
Introduction to Python for Data Science
Introduction to Python for Data ScienceIntroduction to Python for Data Science
Introduction to Python for Data Science
 
20 iOS developer interview questions
20 iOS developer interview questions20 iOS developer interview questions
20 iOS developer interview questions
 
29 Essential AngularJS Interview Questions
29 Essential AngularJS Interview Questions29 Essential AngularJS Interview Questions
29 Essential AngularJS Interview Questions
 
37 Java Interview Questions
37 Java Interview Questions37 Java Interview Questions
37 Java Interview Questions
 
21 Essential JavaScript Interview Questions
21 Essential JavaScript Interview Questions21 Essential JavaScript Interview Questions
21 Essential JavaScript Interview Questions
 
Top 10 Programming Languages in 2015
Top 10 Programming Languages in 2015Top 10 Programming Languages in 2015
Top 10 Programming Languages in 2015
 
How to Build Your App from Scratch
How to Build Your App from ScratchHow to Build Your App from Scratch
How to Build Your App from Scratch
 
Angular meteor for angular devs
Angular meteor for angular devsAngular meteor for angular devs
Angular meteor for angular devs
 
Tmux tips and_tricks
Tmux tips and_tricksTmux tips and_tricks
Tmux tips and_tricks
 
Introduction to Tmux - Codementor Tmux Office Hours Part 1
Introduction to Tmux - Codementor Tmux Office Hours Part 1Introduction to Tmux - Codementor Tmux Office Hours Part 1
Introduction to Tmux - Codementor Tmux Office Hours Part 1
 
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at...
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at...Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at...
Codementor Office Hours with Eric Chiang: Stdin, Stdout: pup, Go, and life at...
 
Python Internals Optimization Choices Made - Codementors Office Hours with St...
Python Internals Optimization Choices Made - Codementors Office Hours with St...Python Internals Optimization Choices Made - Codementors Office Hours with St...
Python Internals Optimization Choices Made - Codementors Office Hours with St...
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 

Building Modern and Secure PHP Applications – Codementor Office Hours with Ben Edmunds