Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Modern & Secure PHP Applications

Modern & Secure PHP Applications

What's new in PHP along with a focus on building secure apps. Presented on CodeMentor 08/12/2014.

Ben Edmunds

August 12, 2014
Tweet

More Decks by Ben Edmunds

Other Decks in Technology

Transcript

  1. Who is this guy? Ben Edmunds ! Open Source Author

    PHP Town Hall Podcast CTO at Mindfulware
  2. PDO

  3. PDO $stmt = $db->prepare(‘ SELECT * FROM users WHERE id=:id

    ’); ! $stmt->bindParam(‘:id’, $id); $stmt->execute();
  4. Security HTTPS / SSL ! Encrypts traffic across the wire

    ! Trusted sender and receiver ! Required by OAUTH 2
  5. Security //safe defaults class Your Controller { protected $var1 =

    ‘default value’; ! function __construct() { … } }
  6. Security //safe defaults $something = false; ! foreach ($array as

    $k => $v) { $something = $v->foo; if ($something == ‘bar’) { … } }
  7. Security //Persistent XSS ! Same idea, except with data that

    is saved to the server and re-displayed
  8. Security //CSRF Protection ! POST / PUT / UPDATE /

    DELETE behind forms with one-time use tokens ! !
  9. Security //CSRF Protection ! function generateCsrf() { $token = mcrypt_create_iv(

    16, MCRYPT_DEV_URANDOM); Session::flash('csrfToken', $token); return $token; }
  10. 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
  11. Unit Testing class ApiAuthTest extends PHPUnit_Framework_TestCase { ! public function

    testVerify() { ! $auth = new apiAuth(); $this->assertTrue($auth->verify());
  12. Unit Testing class ApiAuthTest extends PHPUnit_Framework_TestCase { ! public function

    testVerify() { ! $auth = new apiAuth(); $this->assertTrue($auth->verify());
  13. Unit Testing $ phpunit tests ! PHPUnit 3.3.17 by Sebastian

    Bergmann. Time: 0.01 seconds OK (1 tests, 1 assertions)