|
news and events |
|
2014-07-10
EV1 and The Planet Announce MergerCombination Creates Industry-leading Dedicated Hosting Company; Combined Company Will Continue to Deliver Industry-leading Client Experience
Houston, Texas and Dallas, Texas | May 6, 2006: Everyones Internet (EV1) and The Planet, two leading suppliers of dedicated hosting, declared today they have merged. |
|
|
|
2012-05-28
Vodacom promotion continuesVodacom has extended its MyGig one and MyGig two info contract promotion, which offers 1GB for R99 and 2GB for R149, to 31 July 2012. |
|
client comments |
|
"Great concepts and imaging! Wonderful colour usage, and very modern..."
|
|
|
"Osirion System Technologies surpassed my expectations when it comes to professionalism, service and turn-around efficiency..."
|
|
latest articles |
|
2014-06-14
Nature of the Work About this sectionAn overview and general explanation of Graphic Designers, their job and responsibilities.
|
|
|
2012-02-08
7 Essential Search Engine Optimisation ElementsWhen it comes to Search Engine Optimisation, many companies assume that getting results is as simple as adding keyword-stuffed webpages onto their sites. But there are several factors one should know about...
|
|
We Accept:
|
|
Writing Your Own PHP Function Library
2008-03-24
If you do a lot of web development in PHP, you'll soon notice that you run into the same issues time and time again. Instead of porting a bunch of code from other projects, or spending time working on a problem you've already solved, I recommend building a portable library of custom functions. Obviously your function library will consist of different code then mine, but for the sake of illustrating this in practice I'll outline my some of my function library to illustrate the technique. Since I've used this code in several of my commercial projects, I am releasing the code in this tutorial under the MIT license, which allows you to integrate it into your own projects, both commercial and personal, without royalties.
Let's create a file, we'll call it functions.inc.php Inside this file we're going to define our functions and then we simply include them in any page we need them in.
function am_injection($unprotected) { if (get_magic_quotes_gpc()) { $unprotected = stripslashes($unprotected); } $protected = mysql_real_escape_string($unprotected); return $protected; }
What this function does is it cleans up code for insertion into a MySQL database. Because of the call to mysql_real_escape_string(), a MySQL database connection must be open or this function will fail. Data that is passed to am_injection() through the $unprotected variable is cleaned up and returned ready for SQL. This code doesn't work in versions of PHP lower than 4.3 (not that any web development project should be targeting those versions.) One way to fix that is to put this function in at the beginning of the file:
if (!function_exists("mysql_real_escape_string")) { function mysql_real_escape_string($string, $null=NULL) { return mysql_escape_string($string); } }
This recreates the mysql_real_escape_string function if it doesn't exist.
Now the technique that I've shown you allows you create any function and call it from anywhere in your web development project. You can also do this with object orientated PHP and define classes in this file instead. Either way, once you start creating your own libraries of reusable code, you'll soon find yourself with a lot more free time. You can thank me later.
View other articles in the Web Development category.
View other articles in the PHP sub-category. |