SlideShare a Scribd company logo
1 of 39
Download to read offline
PHP BY THE BOOK
NOT REALLY
PHP BY THE BOOK
IN THE BEGINNING…
PHP BY THE BOOK
IN THE BEGINNING…
PHP BY THE BOOK
SOME TERRIBLE IDEAS
▸ Magic Quotes
▸ Register globals
▸ addslashes
▸ index.php everywhere
▸ Proper OO (private/public)
▸ Dependencies
▸ Standards
SOME MISSING GOOD IDEAS
PHP BY THE BOOK
PHP BY THE BOOK
I LEARNED FROM A BOOK
▸ PHP and MySQL Web
Development
▸ 2005
▸ In my bedroom
▸ Book was great at the time
PHP BY THE BOOK
WHAT’S HAPPENED SINCE 2004
▸ Magic quotes
▸ Symfony
▸ PHP Unit
▸ PEAR
▸ Composer
▸ Packagist
▸ register globals
▸ mysql
▸ pdo
▸ MariaDB
▸ phpStorm
▸ password
hashing api
▸ PHP 5, PHP 5.3, PHP 5.4, PHP 6, PHP 7 (soon!)
▸ “Proper” OO
▸ Unicode
▸ Vagrant
▸ Docker
▸ Easy Peasy CI
▸ github
PHP GOT
EASIER
OLD BOOK IS OLD
PHP BY THE BOOK
EVERYONE USES STACK OVERFLOW ANYWAY… RIGHT?
▸ Google for “hash password php md5”
PHP BY THE BOOK
SQL
▸ Hard and bad and deprecated: mysql_* libraries
▸ Less bad: mysqli_*
▸ Better: PDO
▸ Best: Often Eloquent/Doctrine/Some ORM
▸ These are going to use PDO underneath anyway
PHP BY THE BOOK
IMPROVING THE STACK OVERFLOW ANSWER WITH PDO
/**

* generate a random salt to use for this account

**/

$salt = bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM));



$saltedPW = $_POST['password'] . $salt;



$hashedPW = hash('sha256', $saltedPW);



$query = $pdo->prepare('INSERT INTO user (`name`, hash,
salt) VALUES (:name, :hash, :salt)’);
$query->execute([

'name' => $_POST['name'],

'hash' => $hashedPW,

'salt' => $salt

]);
HASHING
PHP BY THE BOOK
PHP BY THE BOOK
HASHING IS HARD
▸ Salting
▸ algorithms get found out as bad
▸ Rehashing is hard
▸ md5 was once thought secure
▸ Thankfully php 5.5 has password hashing library
▸ Available on php 5.4 via composer
▸ But upgrade your php to >=5.5 instead if you’re on 5.4
PHP BY THE BOOK
MAKE THE HASHING BETTER
$query = $pdo->prepare('INSERT INTO user (email, hash) VALUES
(:email, :hash)');

$query->execute([

'email' => $_POST['email'],

'hash' => password_hash($_POST[‘password’], PASSWORD_DEFAULT)

]);
PHP BY THE BOOK
MAKE THE HASHING BETTER
$query = $pdo->prepare('INSERT INTO user (email, hash) VALUES
(:email, :hash)');

$query->execute([

'email' => $_POST['email'],

'hash' => password_hash($_POST[‘password’], PASSWORD_DEFAULT)

]);
$saltQuery = $pdo->prepare('SELECT hash FROM user WHERE name
= :email');



$result = $saltQuery->execute(['email' => $_POST['email']]);

$hashInDb = $saltQuery->fetch(PDO::FETCH_ASSOC);



if (password_verify($_POST['password'], $hashInDb)) {



if (password_needs_rehash($hashInDb, PASSWORD_DEFAULT)) {

//Rehash the password here...

}

return true;

}
PHP BY THE BOOK
DEPENDENCIES
▸ I made this!
▸ phpclasses.org
▸ Pear
▸ Composer
PHP BY THE BOOK
DEPENDENCIES
▸ I made this!
▸ phpclasses.org
▸ Pear
▸ Composer
PHP BY THE BOOK
DEPENDENCIES
▸ I made this!
▸ phpclasses.org
▸ Pear
▸ Composer
PHP BY THE BOOK
DEPENDENCIES
▸ I made this!
▸ phpclasses.org
▸ Pear
▸ Composer
PHP BY THE BOOK
MEH, USE A LIBRARY
use CartalystSentinelNativeFacadesSentinel;



require_once(dirname(__DIR__).'/vendor/autoload.php');





Sentinel::register([

'email' => $_POST['email'],

'password' => $_POST['password']

]);

PHP BY THE BOOK
MEH, USE A LIBRARY
$credentials = [

'email' => $_POST['email'],

'password' => $_POST['password']

];



Sentinel::authenticate($credentials);

WHAT TIME IS IT?
PHP BY THE BOOK
PHP BY THE BOOK: WHAT TIME IS IT
MTKIME
PHP BY THE BOOK: WHAT TIME IS IT
USING MKTIME
<?php



$numberOfMonths = 12;



$dates = [];

$monthlyResults = [];





for ($i = 0; $i < $numberOfMonths; $i++) {

$date = mktime(null, null, null, date('n') + $i);



$monthlyResults[] = [

'date' => $date,

'results' => getResults(date('m', $date), date('Y', $date))

];

}








PHP BY THE BOOK: WHAT TIME IS IT
USING MKTIME
...

foreach ($monthlyResults as $resultSet) {

?>

<tr>

<td> <?php echo date('m Y', $resultSet['date']); ?>
</td>

<td> <?php echo $resultSet['results']; ?> </td>

</tr>

<?php

}

?>


PHP BY THE BOOK: WHAT TIME IS IT
USING MTKIME - CHANGING TO 4 WEEKS
<?php



$dates = [];

$monthlyResults = [];



$endDate = mktime(null, null, null, null, null, date('Y') + 1);

$i = 0;



do {



$date = mktime(null, null, null, null, date('d') + ($i * 28));



$monthlyResults[] = [

'date' => $date,

'results' => getResults($date)

];



$i++;

} while ($date <= $endDate);





PHP BY THE BOOK: WHAT TIME IS IT
WITH DATETIME
<?php



$numberOfMonths = 12;



$endDate = new DateTime();

$endDate->add(new DateInterval('P' . $numberOfMonths .
'M'));



$dates = new DatePeriod(new DateTime('now'), new
DateInterval('P1M'), $endDate);



foreach ($dates as $date) {



$monthlyResults[] = [

'date' => $date,

'results' => getResults($date)

];

}

PHP BY THE BOOK: WHAT TIME IS IT
WITH DATETIME
<?php

foreach ($monthlyResults as $resultSet) {

?>

<tr>

<td> <?php echo $resultSet['date']->format('m Y'); ?> </td>

<td> <?php echo $resultSet['results']; ?> </td>

</tr>

<?php

}

?>
PHP BY THE BOOK: WHAT TIME IS IT
WITH DATETIME - CHANGING TO 4 WEEKS
<?php



$endDate = new DateTime();

$endDate->add(new DateInterval('P1Y'));



$dates = new DatePeriod(new DateTime('now'), new
DateInterval('P28D'), $endDate);



foreach ($dates as $date) {



$monthlyResults[] = [

'date' => $date,

'results' => getResults($date)

];

}






MOAR!!!!!
PHP BY THE BOOK: 

TEMPLATES & CARBON
PHP BY THE BOOK
STANDARDS - PHP-FIG / PSR
▸ Loads of these
▸ autoloading (PSR-0 & 

PSR-4)
▸ Coding (PSR-1 & PSR-2)
▸ Logging (PSR-3)
▸ HTTP Messages (PSR-7)
▸ More on the way…
WWW.PHP-FIG.ORG
PHP BY THE BOOK
NON CODE STUFF
▸ Unit Tests and CI
▸ Tools
RESPONSIBILITIES
PHP BY THE BOOK
PHP BY THE BOOK: RESPONSIBILITIES
STAYING ON TOP
▸ Modern PHP - Josh Lockhart
▸ Read the php release announcements
▸ Community
▸ especially in work
PHP BY THE BOOK: RESPONSIBILITIES
HELPING OTHER DEVELOPERS
▸ Talk to each other
▸ Tech talks in house
▸ Show off a bit
▸ Pair Programming
▸ Ping Pong?
▸ Who do you send to Conferences?
NO-ONE IS "SELF-TAUGHT" YOU ARE
COMMUNITY-TAUGHT - YOU LEARNED FROM
THE BLOG POSTS & EXAMPLE CODE OF
OTHERS.
JOIN YOUR LOCAL #PHPUG
@phpbelfast
PHP BY THE BOOK: RESPONSIBILITIES
PHP BY THE BOOK
FURTHER READING
▸ goo.gl/nv2YUb - 7 ways to screw up
bcrypt
▸ php-fig.org
▸ goo.gl/EBEACo - the Stack question
▸ Modern PHP - Josh Lockhart
PHP BY THE BOOK
GETTING IN TOUCH
▸ @ryankilf
▸ norniron.slack.com #phpbelfast
▸ joind.in/15861

More Related Content

What's hot

Future of HTTP in CakePHP
Future of HTTP in CakePHPFuture of HTTP in CakePHP
Future of HTTP in CakePHPmarkstory
 
Service intergration
Service intergration Service intergration
Service intergration 재민 장
 
Path::Tiny
Path::TinyPath::Tiny
Path::Tinywaniji
 
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
 
Darkmira Tour PHP 2016 - Automatizando Tarefas com Phing
Darkmira Tour PHP 2016 - Automatizando Tarefas com PhingDarkmira Tour PHP 2016 - Automatizando Tarefas com Phing
Darkmira Tour PHP 2016 - Automatizando Tarefas com PhingMatheus Marabesi
 
与 PHP 和 Perl 使用 MySQL 数据库
与 PHP 和 Perl 使用 MySQL 数据库与 PHP 和 Perl 使用 MySQL 数据库
与 PHP 和 Perl 使用 MySQL 数据库YUCHENG HU
 
Uncovering Iterators
Uncovering IteratorsUncovering Iterators
Uncovering Iteratorssdevalk
 
Up.Php
Up.PhpUp.Php
Up.Phpwsoom
 
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
 
Client-side Storage 
Client-side Storage Client-side Storage 
Client-side Storage Tobias Wolf
 
PuppetCamp SEA @ Blk 71 - Nagios in under 10 mins with Puppet
PuppetCamp SEA @ Blk 71 -  Nagios in under 10 mins with PuppetPuppetCamp SEA @ Blk 71 -  Nagios in under 10 mins with Puppet
PuppetCamp SEA @ Blk 71 - Nagios in under 10 mins with PuppetWalter Heck
 
PuppetCamp SEA @ Blk 71 - Nagios in under 10 mins with Puppet
PuppetCamp SEA @ Blk 71 -  Nagios in under 10 mins with PuppetPuppetCamp SEA @ Blk 71 -  Nagios in under 10 mins with Puppet
PuppetCamp SEA @ Blk 71 - Nagios in under 10 mins with PuppetOlinData
 

What's hot (20)

Php Mysql
Php Mysql Php Mysql
Php Mysql
 
Future of HTTP in CakePHP
Future of HTTP in CakePHPFuture of HTTP in CakePHP
Future of HTTP in CakePHP
 
Service intergration
Service intergration Service intergration
Service intergration
 
Redis
RedisRedis
Redis
 
Path::Tiny
Path::TinyPath::Tiny
Path::Tiny
 
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
 
Darkmira Tour PHP 2016 - Automatizando Tarefas com Phing
Darkmira Tour PHP 2016 - Automatizando Tarefas com PhingDarkmira Tour PHP 2016 - Automatizando Tarefas com Phing
Darkmira Tour PHP 2016 - Automatizando Tarefas com Phing
 
My First Ruby
My First RubyMy First Ruby
My First Ruby
 
与 PHP 和 Perl 使用 MySQL 数据库
与 PHP 和 Perl 使用 MySQL 数据库与 PHP 和 Perl 使用 MySQL 数据库
与 PHP 和 Perl 使用 MySQL 数据库
 
Advanced Querying with CakePHP 3
Advanced Querying with CakePHP 3Advanced Querying with CakePHP 3
Advanced Querying with CakePHP 3
 
Uncovering Iterators
Uncovering IteratorsUncovering Iterators
Uncovering Iterators
 
Up.Php
Up.PhpUp.Php
Up.Php
 
Tax management-system
Tax management-systemTax management-system
Tax management-system
 
PHP Lecture 6 - Php file uploading
PHP Lecture 6 - Php file uploadingPHP Lecture 6 - Php file uploading
PHP Lecture 6 - Php file uploading
 
File system
File systemFile system
File system
 
Wsomdp
WsomdpWsomdp
Wsomdp
 
My shell
My shellMy shell
My shell
 
Client-side Storage 
Client-side Storage Client-side Storage 
Client-side Storage 
 
PuppetCamp SEA @ Blk 71 - Nagios in under 10 mins with Puppet
PuppetCamp SEA @ Blk 71 -  Nagios in under 10 mins with PuppetPuppetCamp SEA @ Blk 71 -  Nagios in under 10 mins with Puppet
PuppetCamp SEA @ Blk 71 - Nagios in under 10 mins with Puppet
 
PuppetCamp SEA @ Blk 71 - Nagios in under 10 mins with Puppet
PuppetCamp SEA @ Blk 71 -  Nagios in under 10 mins with PuppetPuppetCamp SEA @ Blk 71 -  Nagios in under 10 mins with Puppet
PuppetCamp SEA @ Blk 71 - Nagios in under 10 mins with Puppet
 

Viewers also liked

Developing the World's Less Fortunate Majority - Case Study on the UNDP
Developing the World's Less Fortunate Majority - Case Study on the UNDPDeveloping the World's Less Fortunate Majority - Case Study on the UNDP
Developing the World's Less Fortunate Majority - Case Study on the UNDPRussell White
 
Sistemas operativos
Sistemas operativosSistemas operativos
Sistemas operativosmoises168
 
REAS 2014 - Evoluzione Incendi da fulmine in FVG
REAS 2014 - Evoluzione Incendi da fulmine in FVGREAS 2014 - Evoluzione Incendi da fulmine in FVG
REAS 2014 - Evoluzione Incendi da fulmine in FVGGruppo AIB Italia
 
Catalizador transformador de co2 en metanol
Catalizador transformador de co2 en metanolCatalizador transformador de co2 en metanol
Catalizador transformador de co2 en metanolJorge Ozuna
 
DMI – Tres herramientas que harán visible tu negocio en internet
DMI – Tres herramientas que harán visible tu negocio en internetDMI – Tres herramientas que harán visible tu negocio en internet
DMI – Tres herramientas que harán visible tu negocio en internetPalmaActiva
 
Proyecto Nacional Seguridad Albañileria
Proyecto Nacional Seguridad AlbañileriaProyecto Nacional Seguridad Albañileria
Proyecto Nacional Seguridad Albañileriajuanrivasgo
 
Examen abierto nacional por Internet OMI 2001
Examen abierto nacional por Internet OMI 2001Examen abierto nacional por Internet OMI 2001
Examen abierto nacional por Internet OMI 2001MaryRomero77
 
Nc6 a -toledo
Nc6 a -toledoNc6 a -toledo
Nc6 a -toledordiez7
 
Web Marketing Framework - Web Success Agency
Web Marketing Framework - Web Success AgencyWeb Marketing Framework - Web Success Agency
Web Marketing Framework - Web Success AgencyBPAS
 
DITA Workflow 101- An Action Plan for DITA Implementation
DITA Workflow 101- An Action Plan for DITA ImplementationDITA Workflow 101- An Action Plan for DITA Implementation
DITA Workflow 101- An Action Plan for DITA ImplementationJANA, Inc.
 
Energy-Balanced Dispatch of Mobile Sensors in a Hybrid Wireless Sensor Network
Energy-Balanced Dispatch of Mobile Sensors in a Hybrid Wireless Sensor NetworkEnergy-Balanced Dispatch of Mobile Sensors in a Hybrid Wireless Sensor Network
Energy-Balanced Dispatch of Mobile Sensors in a Hybrid Wireless Sensor Networkambitlick
 
COLLINS KIPKOECH TOGOM CV
COLLINS KIPKOECH TOGOM CVCOLLINS KIPKOECH TOGOM CV
COLLINS KIPKOECH TOGOM CVCOLLINS TOGOM
 

Viewers also liked (18)

MGT 311 Final Exam 2015 version
MGT 311 Final Exam 2015 versionMGT 311 Final Exam 2015 version
MGT 311 Final Exam 2015 version
 
Відкритий урок
Відкритий урокВідкритий урок
Відкритий урок
 
Library qualifications
Library qualificationsLibrary qualifications
Library qualifications
 
Developing the World's Less Fortunate Majority - Case Study on the UNDP
Developing the World's Less Fortunate Majority - Case Study on the UNDPDeveloping the World's Less Fortunate Majority - Case Study on the UNDP
Developing the World's Less Fortunate Majority - Case Study on the UNDP
 
Sistemas operativos
Sistemas operativosSistemas operativos
Sistemas operativos
 
REAS 2014 - Evoluzione Incendi da fulmine in FVG
REAS 2014 - Evoluzione Incendi da fulmine in FVGREAS 2014 - Evoluzione Incendi da fulmine in FVG
REAS 2014 - Evoluzione Incendi da fulmine in FVG
 
Trackables
TrackablesTrackables
Trackables
 
Catalizador transformador de co2 en metanol
Catalizador transformador de co2 en metanolCatalizador transformador de co2 en metanol
Catalizador transformador de co2 en metanol
 
DMI – Tres herramientas que harán visible tu negocio en internet
DMI – Tres herramientas que harán visible tu negocio en internetDMI – Tres herramientas que harán visible tu negocio en internet
DMI – Tres herramientas que harán visible tu negocio en internet
 
Proyecto Nacional Seguridad Albañileria
Proyecto Nacional Seguridad AlbañileriaProyecto Nacional Seguridad Albañileria
Proyecto Nacional Seguridad Albañileria
 
Examen abierto nacional por Internet OMI 2001
Examen abierto nacional por Internet OMI 2001Examen abierto nacional por Internet OMI 2001
Examen abierto nacional por Internet OMI 2001
 
Nc6 a -toledo
Nc6 a -toledoNc6 a -toledo
Nc6 a -toledo
 
Web Marketing Framework - Web Success Agency
Web Marketing Framework - Web Success AgencyWeb Marketing Framework - Web Success Agency
Web Marketing Framework - Web Success Agency
 
DITA Workflow 101- An Action Plan for DITA Implementation
DITA Workflow 101- An Action Plan for DITA ImplementationDITA Workflow 101- An Action Plan for DITA Implementation
DITA Workflow 101- An Action Plan for DITA Implementation
 
Emprendedor 2.0 - Acelera tus ventas con internet
Emprendedor 2.0 - Acelera tus ventas con internetEmprendedor 2.0 - Acelera tus ventas con internet
Emprendedor 2.0 - Acelera tus ventas con internet
 
Energy-Balanced Dispatch of Mobile Sensors in a Hybrid Wireless Sensor Network
Energy-Balanced Dispatch of Mobile Sensors in a Hybrid Wireless Sensor NetworkEnergy-Balanced Dispatch of Mobile Sensors in a Hybrid Wireless Sensor Network
Energy-Balanced Dispatch of Mobile Sensors in a Hybrid Wireless Sensor Network
 
COLLINS KIPKOECH TOGOM CV
COLLINS KIPKOECH TOGOM CVCOLLINS KIPKOECH TOGOM CV
COLLINS KIPKOECH TOGOM CV
 
NextDeeksha-Final web format
NextDeeksha-Final web formatNextDeeksha-Final web format
NextDeeksha-Final web format
 

Similar to Not Really PHP by the book

Php 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the GoodPhp 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the GoodJeremy Kendall
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistenceHugo Hamon
 
Iterators & generators: practical uses in memory management
Iterators & generators: practical uses in memory managementIterators & generators: practical uses in memory management
Iterators & generators: practical uses in memory managementAdrian Cardenas
 
[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?Radek Benkel
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboardsDenis Ristic
 
Generated Power: PHP 5.5 Generators
Generated Power: PHP 5.5 GeneratorsGenerated Power: PHP 5.5 Generators
Generated Power: PHP 5.5 GeneratorsMark Baker
 
Electrify your code with PHP Generators
Electrify your code with PHP GeneratorsElectrify your code with PHP Generators
Electrify your code with PHP GeneratorsMark Baker
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHPNat Weerawan
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐいHisateru Tanaka
 
Phpspec tips&amp;tricks
Phpspec tips&amp;tricksPhpspec tips&amp;tricks
Phpspec tips&amp;tricksFilip Golonka
 
Quick beginner to Lower-Advanced guide/tutorial in PHP
Quick beginner to Lower-Advanced guide/tutorial in PHPQuick beginner to Lower-Advanced guide/tutorial in PHP
Quick beginner to Lower-Advanced guide/tutorial in PHPSanju Sony Kurian
 
Introducation to php for beginners
Introducation to php for beginners Introducation to php for beginners
Introducation to php for beginners musrath mohammad
 

Similar to Not Really PHP by the book (20)

Php 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the GoodPhp 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the Good
 
PHP POWERPOINT SLIDES
PHP POWERPOINT SLIDESPHP POWERPOINT SLIDES
PHP POWERPOINT SLIDES
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
 
Php hacku
Php hackuPhp hacku
Php hacku
 
Iterators & generators: practical uses in memory management
Iterators & generators: practical uses in memory managementIterators & generators: practical uses in memory management
Iterators & generators: practical uses in memory management
 
Intro to PHP
Intro to PHPIntro to PHP
Intro to PHP
 
[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
 
Generated Power: PHP 5.5 Generators
Generated Power: PHP 5.5 GeneratorsGenerated Power: PHP 5.5 Generators
Generated Power: PHP 5.5 Generators
 
PHP code examples
PHP code examplesPHP code examples
PHP code examples
 
Ip lab
Ip labIp lab
Ip lab
 
Blog Hacks 2011
Blog Hacks 2011Blog Hacks 2011
Blog Hacks 2011
 
Electrify your code with PHP Generators
Electrify your code with PHP GeneratorsElectrify your code with PHP Generators
Electrify your code with PHP Generators
 
Php talk
Php talkPhp talk
Php talk
 
PHP for hacks
PHP for hacksPHP for hacks
PHP for hacks
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Phpspec tips&amp;tricks
Phpspec tips&amp;tricksPhpspec tips&amp;tricks
Phpspec tips&amp;tricks
 
Quick beginner to Lower-Advanced guide/tutorial in PHP
Quick beginner to Lower-Advanced guide/tutorial in PHPQuick beginner to Lower-Advanced guide/tutorial in PHP
Quick beginner to Lower-Advanced guide/tutorial in PHP
 
Introducation to php for beginners
Introducation to php for beginners Introducation to php for beginners
Introducation to php for beginners
 

Recently uploaded

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

Not Really PHP by the book

  • 1. PHP BY THE BOOK NOT REALLY
  • 2. PHP BY THE BOOK IN THE BEGINNING…
  • 3. PHP BY THE BOOK IN THE BEGINNING…
  • 4. PHP BY THE BOOK SOME TERRIBLE IDEAS ▸ Magic Quotes ▸ Register globals ▸ addslashes ▸ index.php everywhere ▸ Proper OO (private/public) ▸ Dependencies ▸ Standards SOME MISSING GOOD IDEAS
  • 5. PHP BY THE BOOK
  • 6. PHP BY THE BOOK I LEARNED FROM A BOOK ▸ PHP and MySQL Web Development ▸ 2005 ▸ In my bedroom ▸ Book was great at the time
  • 7. PHP BY THE BOOK WHAT’S HAPPENED SINCE 2004 ▸ Magic quotes ▸ Symfony ▸ PHP Unit ▸ PEAR ▸ Composer ▸ Packagist ▸ register globals ▸ mysql ▸ pdo ▸ MariaDB ▸ phpStorm ▸ password hashing api ▸ PHP 5, PHP 5.3, PHP 5.4, PHP 6, PHP 7 (soon!) ▸ “Proper” OO ▸ Unicode ▸ Vagrant ▸ Docker ▸ Easy Peasy CI ▸ github
  • 10. PHP BY THE BOOK EVERYONE USES STACK OVERFLOW ANYWAY… RIGHT? ▸ Google for “hash password php md5”
  • 11. PHP BY THE BOOK SQL ▸ Hard and bad and deprecated: mysql_* libraries ▸ Less bad: mysqli_* ▸ Better: PDO ▸ Best: Often Eloquent/Doctrine/Some ORM ▸ These are going to use PDO underneath anyway
  • 12. PHP BY THE BOOK IMPROVING THE STACK OVERFLOW ANSWER WITH PDO /**
 * generate a random salt to use for this account
 **/
 $salt = bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM));
 
 $saltedPW = $_POST['password'] . $salt;
 
 $hashedPW = hash('sha256', $saltedPW);
 
 $query = $pdo->prepare('INSERT INTO user (`name`, hash, salt) VALUES (:name, :hash, :salt)’); $query->execute([
 'name' => $_POST['name'],
 'hash' => $hashedPW,
 'salt' => $salt
 ]);
  • 14. PHP BY THE BOOK HASHING IS HARD ▸ Salting ▸ algorithms get found out as bad ▸ Rehashing is hard ▸ md5 was once thought secure ▸ Thankfully php 5.5 has password hashing library ▸ Available on php 5.4 via composer ▸ But upgrade your php to >=5.5 instead if you’re on 5.4
  • 15. PHP BY THE BOOK MAKE THE HASHING BETTER $query = $pdo->prepare('INSERT INTO user (email, hash) VALUES (:email, :hash)');
 $query->execute([
 'email' => $_POST['email'],
 'hash' => password_hash($_POST[‘password’], PASSWORD_DEFAULT)
 ]);
  • 16. PHP BY THE BOOK MAKE THE HASHING BETTER $query = $pdo->prepare('INSERT INTO user (email, hash) VALUES (:email, :hash)');
 $query->execute([
 'email' => $_POST['email'],
 'hash' => password_hash($_POST[‘password’], PASSWORD_DEFAULT)
 ]); $saltQuery = $pdo->prepare('SELECT hash FROM user WHERE name = :email');
 
 $result = $saltQuery->execute(['email' => $_POST['email']]);
 $hashInDb = $saltQuery->fetch(PDO::FETCH_ASSOC);
 
 if (password_verify($_POST['password'], $hashInDb)) {
 
 if (password_needs_rehash($hashInDb, PASSWORD_DEFAULT)) {
 //Rehash the password here...
 }
 return true;
 }
  • 17. PHP BY THE BOOK DEPENDENCIES ▸ I made this! ▸ phpclasses.org ▸ Pear ▸ Composer
  • 18. PHP BY THE BOOK DEPENDENCIES ▸ I made this! ▸ phpclasses.org ▸ Pear ▸ Composer
  • 19. PHP BY THE BOOK DEPENDENCIES ▸ I made this! ▸ phpclasses.org ▸ Pear ▸ Composer
  • 20. PHP BY THE BOOK DEPENDENCIES ▸ I made this! ▸ phpclasses.org ▸ Pear ▸ Composer
  • 21. PHP BY THE BOOK MEH, USE A LIBRARY use CartalystSentinelNativeFacadesSentinel;
 
 require_once(dirname(__DIR__).'/vendor/autoload.php');
 
 
 Sentinel::register([
 'email' => $_POST['email'],
 'password' => $_POST['password']
 ]);

  • 22. PHP BY THE BOOK MEH, USE A LIBRARY $credentials = [
 'email' => $_POST['email'],
 'password' => $_POST['password']
 ];
 
 Sentinel::authenticate($credentials);

  • 23. WHAT TIME IS IT? PHP BY THE BOOK
  • 24. PHP BY THE BOOK: WHAT TIME IS IT MTKIME
  • 25. PHP BY THE BOOK: WHAT TIME IS IT USING MKTIME <?php
 
 $numberOfMonths = 12;
 
 $dates = [];
 $monthlyResults = [];
 
 
 for ($i = 0; $i < $numberOfMonths; $i++) {
 $date = mktime(null, null, null, date('n') + $i);
 
 $monthlyResults[] = [
 'date' => $date,
 'results' => getResults(date('m', $date), date('Y', $date))
 ];
 } 
 
 
 

  • 26. PHP BY THE BOOK: WHAT TIME IS IT USING MKTIME ...
 foreach ($monthlyResults as $resultSet) {
 ?>
 <tr>
 <td> <?php echo date('m Y', $resultSet['date']); ?> </td>
 <td> <?php echo $resultSet['results']; ?> </td>
 </tr>
 <?php
 }
 ?> 

  • 27. PHP BY THE BOOK: WHAT TIME IS IT USING MTKIME - CHANGING TO 4 WEEKS <?php
 
 $dates = [];
 $monthlyResults = [];
 
 $endDate = mktime(null, null, null, null, null, date('Y') + 1);
 $i = 0;
 
 do {
 
 $date = mktime(null, null, null, null, date('d') + ($i * 28));
 
 $monthlyResults[] = [
 'date' => $date,
 'results' => getResults($date)
 ];
 
 $i++;
 } while ($date <= $endDate);
 
 

  • 28. PHP BY THE BOOK: WHAT TIME IS IT WITH DATETIME <?php
 
 $numberOfMonths = 12;
 
 $endDate = new DateTime();
 $endDate->add(new DateInterval('P' . $numberOfMonths . 'M'));
 
 $dates = new DatePeriod(new DateTime('now'), new DateInterval('P1M'), $endDate);
 
 foreach ($dates as $date) {
 
 $monthlyResults[] = [
 'date' => $date,
 'results' => getResults($date)
 ];
 }

  • 29. PHP BY THE BOOK: WHAT TIME IS IT WITH DATETIME <?php
 foreach ($monthlyResults as $resultSet) {
 ?>
 <tr>
 <td> <?php echo $resultSet['date']->format('m Y'); ?> </td>
 <td> <?php echo $resultSet['results']; ?> </td>
 </tr>
 <?php
 }
 ?>
  • 30. PHP BY THE BOOK: WHAT TIME IS IT WITH DATETIME - CHANGING TO 4 WEEKS <?php
 
 $endDate = new DateTime();
 $endDate->add(new DateInterval('P1Y'));
 
 $dates = new DatePeriod(new DateTime('now'), new DateInterval('P28D'), $endDate);
 
 foreach ($dates as $date) {
 
 $monthlyResults[] = [
 'date' => $date,
 'results' => getResults($date)
 ];
 } 
 
 

  • 31. MOAR!!!!! PHP BY THE BOOK: 
 TEMPLATES & CARBON
  • 32. PHP BY THE BOOK STANDARDS - PHP-FIG / PSR ▸ Loads of these ▸ autoloading (PSR-0 & 
 PSR-4) ▸ Coding (PSR-1 & PSR-2) ▸ Logging (PSR-3) ▸ HTTP Messages (PSR-7) ▸ More on the way… WWW.PHP-FIG.ORG
  • 33. PHP BY THE BOOK NON CODE STUFF ▸ Unit Tests and CI ▸ Tools
  • 35. PHP BY THE BOOK: RESPONSIBILITIES STAYING ON TOP ▸ Modern PHP - Josh Lockhart ▸ Read the php release announcements ▸ Community ▸ especially in work
  • 36. PHP BY THE BOOK: RESPONSIBILITIES HELPING OTHER DEVELOPERS ▸ Talk to each other ▸ Tech talks in house ▸ Show off a bit ▸ Pair Programming ▸ Ping Pong? ▸ Who do you send to Conferences?
  • 37. NO-ONE IS "SELF-TAUGHT" YOU ARE COMMUNITY-TAUGHT - YOU LEARNED FROM THE BLOG POSTS & EXAMPLE CODE OF OTHERS. JOIN YOUR LOCAL #PHPUG @phpbelfast PHP BY THE BOOK: RESPONSIBILITIES
  • 38. PHP BY THE BOOK FURTHER READING ▸ goo.gl/nv2YUb - 7 ways to screw up bcrypt ▸ php-fig.org ▸ goo.gl/EBEACo - the Stack question ▸ Modern PHP - Josh Lockhart
  • 39. PHP BY THE BOOK GETTING IN TOUCH ▸ @ryankilf ▸ norniron.slack.com #phpbelfast ▸ joind.in/15861