Skip to Content
PHP Hacks
book

PHP Hacks

by Jack D. Herrington
December 2005
Intermediate to advanced
468 pages
9h 12m
English
O'Reilly Media, Inc.
Content preview from PHP Hacks

Chapter 6. Application Design

Hacks 51–66: Introduction

Sitting on top of the database and below the HTML is application logic. This chapter concentrates on hacks that will add stability and flexibility to your application logic. Topics covered include security and roles, password management, login and session management, and e-commerce.

Create Modular Interfaces

Use dynamic loading to allow users to write snap-in modules for your application.

Most of the really popular PHP open source applications have an extension mechanism that allows for PHP coders to write small fragments of code that are dynamically loaded into the application. This hack demonstrates an XML-based drawing script that you can extend simply by placing new PHP classes into a modules directory; of course, the point is not as much the drawing code as the way you can extend it easily.

The Code

Save the code in Example 6-1 as modhost.php.

Example 6-1. The code that handles a modular PHP architecture
<?php class DrawingEnvironment { private $img = null; private $x = null; private $y = null; private $colors = array(); public function __construct( $x, $y ) { $this->img = imagecreatetruecolor( $x, $y ); $this->addColor( 'white', 255, 255, 255 ); $this->addColor( 'black', 0, 0, 0 ); $this->addColor( 'red', 255, 0, 0 ); $this->addColor( 'green', 0, 255, 0 ); $this->addColor( 'blue', 0, 0, 255 ); imagefilledrectangle( $this->image(), 0, 0, $x, $y, $this->color( 'white' ) ); } public function image() { return $this->img; } public ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

PHP 5 Unleashed

PHP 5 Unleashed

John Coggeshall
PHP Master

PHP Master

Davey Shafik, Lorna Mitchell, Matthew Turland
Pro PHP Programming

Pro PHP Programming

Peter MacIntyre, Brian Danchilla, Mladen Gogala

Publisher Resources

ISBN: 0596101392Errata Page