Thursday, January 10th, 2008

PHP HTTPRequest Class

Note: This is is a quick example of a very basic HTTP Request Class in PHP. This would be a nice, practical introduction to classes for someone who has been looking for a place to start.

Problem: By default, request data in PHP is handled by using Super Globals ($_POST, $_GET, $_COOKIES). Globals are bad for several reasons (outside the scope of this example google here). In an effort to remedy this, we need a way to encapsulate the request data into an object. By doing this, we are centralising access to request data through the one channel - the HTTP Request object.

Class Name:HTTPRequest

Responsibilities:

  • Store “request data” in GPC order.
  • Store additional “request data” outside of the super globals referenced by a key.
  • Read stored “request data” by referencing a key.
  • Internally clean request data by handling magic_quotes_gpc and then adding slashes.
  • Allow access to data stored in GET, POST and COOKIE super globals.

Collaborators: Any - the request object is used by any other class or function that requires access to the request data.

More…

2 comments » Filed under Classes & Examples by rvdavid at 11:49.

back to top

Thursday, December 6th, 2007

Classes & Examples Sub-Category

I’ve created a “Classes & Examples” sub category for PHP. This category will be different from actual Design Patterns in a  way that these will be more practical examples which you can modify and use in your own code base (all I ask is that you leave my name somewhere in the credits).

The Posts I will be making in the “Classes & Examples” Sub-Category will be formatted in the following way:

More…

Leave a comment » Filed under Classes & Examples by rvdavid at 0:22.

back to top

Credits:

© rvdavid blogs: Web Development | Powered by WP 2.3.1

Tree theme modified based on headsetoptions