Beginners PHP

Welcome to Beginners PHP, on this site you will find various source code snippets, books, tutorials and articles and links for PHP. As you can see we have re-designed the layout.

We are starting to revamp our Downloads area. The aim of this is to have more useful freeware and shareware related to PHP and MySQL in the one location


We have collected various sample chapters in time, our collection is available at Sample book Chapters

We have started a new source code section called CMS, this will have various code snippets for CMS such as Wordpress, joomla and various others


We decided to publish some of the simple wordpress plugins that we use on sone of our Wordpress blogs, these are free to download and are unencrypted. Hopefully some of the techniques can be used in your own plugins and they are PHP related. Visit our plugin page here.


We have created a Wordpress blog where we shall show some of these plugins in action and post updated news. You can visit that at Beginners PHP Wordpress blog


A This is our basic series of PHP and MySQL tutorials on various PHP subjects, the first couple have been completed and are already in place. Visit our PHP and MySQL tutorial section.


Some of our tutorials are listed at Tutorials2u : the tutorial directory, this is another site run by us and of course if you have any tutorials or know any good tutorials then pay it a visit and submit them.


You can now display our latest code snippets on your own website by using our PHP categorised RSS feeds, check out the feeds that we have available by visiting theBeginners php RSS feeds section


We have completed relaunched our PHP script directory section and there are now 10000 listings in it and a different look and feel, of course new listings can be submitted and will be reviewed and include. Take a look at our PHP script directory and see.



Random Code Example

Dynamic title tags(Wordpress)
Random Amazon book link(randomizing)
Using trim to get rid of whitespace(string)
Check number of characters(string)
watermark an image example(image)

Random Article

Bring Your Web Site to Life With PHP
Autoresponders With PHP

Random Download

vs PHP 2002


Looking for low cost domain names then try our store with a wide range of tld's, website hosting, email addresses for business and a whole load of other fantastic offerings. Domain name store

Books :

Sponsors :

Random Code :

getprotobynumber function(functions)
Counter example(application)
Processor information(functions)

Random Article :

For Automated Sites PHP and MySQL are A Perfect Match
How to Implement CAPTCHA With PHP and GD

So, you have a submission form on your website and need to prevent spam by auto-submitters. The most common way to do this is to implement CAPTCHA - an image with a randomly generated string (quote from Wikipedia, free online enciclopedia: “A CAPTCHA is a type of challenge-response test used in computing to determine whether the user is human. "CAPTCHA" is an acronym for "Completely Automated Public Turing test to tell Computers and Humans Apart", trademarked by Carnegie Mellon University.”)

Simple, quick and efficient PHP solution for implement CAPTCHA:

the advantage of this solution: it is easy to read symbols by human and automated captcha processor software, but hard to process the image by computer because common CAPTCHA processors can't understand which one of the outputted symbols it must ignore!

obviously you need PHP engine enabled for your webserver, for execute PHP scripts, and GD (PHP graphics library) for generate the image. Webserver, PHP and GD versions are no matter, the solution below is tested for Apache(Windows and Unix), IIS(Windows), PHP-4, PHP-5, GD, GD2

1) Make a PHP script (separate file captcha.php) which will generate the CAPTCHA image:
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
function _generateRandom($length=6){
$_rand_src = array(
array(48,57) //digits
, array(97,122) //lowercase chars
// , array(65,90) //uppercase chars
srand ((double) microtime() * 1000000);
$random_string = "";
$random_string .= chr(rand($_rand_src[$i1][0],$_rand_src[$i1][1]));
return $random_string;
$im = @imagecreatefromjpeg("captcha.jpg");
$rand = _generateRandom(3);
$_SESSION['captcha'] = $rand;
ImageString($im, 5, 2, 2, $rand[0]." ".$rand[1]." ".$rand[2]." ", ImageColorAllocate ($im, 0, 0, 0));
$rand = _generateRandom(3);
ImageString($im, 5, 2, 2, " ".$rand[0]." ".$rand[1]." ".$rand[2], ImageColorAllocate ($im, 255, 0, 0));
Header ('Content-type: image/jpeg');

2) Add the following line at the top of the page where you need to implement the CAPTCHA (there should not be any output before this line, except you use php functions ob_start() and ob_end_flush() to turn on output buffering):
[?php session_start(); ?]

3) Add the following line for check is CAPTCHA entered by visitor valid, before the line where you will proceed submitted message:
[?php if($_SESSION["captcha"]==$_POST["captcha"])
//CAPTHCA is valid; proceed the message: save to database, send by e-mail ...
echo 'CAPTHCA is valid; proceed the message';
else {

echo 'CAPTHCA is not valid; ignore submission'; }?]

4) Finaly add the CAPTCHA to the form:
[img src="captcha.php" alt="captcha image"][input type="text" name="captcha" size="3" maxlength="3"]

- the tags "[?" and "?]" in code samples above should be replaced to the "", you may download original article and code sample here: free download php captcha demo

- requirements: a webserver (windows or linux no matter) with PHP engine, with GD (graphic library) support, you may check your php settings with phpinfo() function

- you need some blank jpg image for use it as background for CAPTCHA string


Programming resources
Tutorials directory
Hosting resources
ASP site
Domain names
Maxi directory
bigarticle : free articles
A Code
Code N Tutorials
Programmers help