WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : a little counter-script for PHP. Needs the gd-library and Colors.php
Categories : Graphics, PHP, Complete Programs Update Picture
Claus Radloff
Date : Jan 17th 1999
Grade : 3 of 5 (graded 5 times)
Viewed : 19801
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Claus Radloff
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?
/////////////////////////////////////////////////////////////////////////
//
// counter.php - implements a simple Counter
//
// Author: Claus Radloff
//
// Description:
// The counter in this file can count multiple counters. Therefore
// every counter gets it´s own identifier.
// The Fore- and Backgroundcolor and the number of digits are
// defined, but can be overwritten. Fore- and Backgroundcolor may
// be transparent as well.
// The Parameters are passed in the URL.
// Some Examples:
// simple counter:
// <img src="counter.php?Identifier=Test">
//
// Counter with red background
// <img src="counter.php?Identifier=Test&BGColor=255+0+0">
// or:
// <img src="counter.php?Identifier=Test&BGColor=red">
//
// Counter with red background, green foreground and 4 digits
// <img src="counter.php?Identifier=Test&BGColor=255+0+0&FGColor=0+255+0&Length=4">
// or:
// <img src="counter.php?Identifier=Test&BGColor=red&FGColor=green&Length=4">
//
// Counter with transparent background and red foreground
// <img src="counter.php?Identifier=Test&BGColor=transparent&FGColor=red">
//

Header( "Content-type: image/gif");

require( "colors.php");

// Load the gd-library
// under Windooze use this one
// dl("php3_gd.dll");
// under UNIX use this one
dl( "php3_gd.so");

// some default-values
$Font = 5;
$BGColor = GetColor( "black");
$BGTrans = False;
$FGColor = GetColor( "white");
$FGTrans = False;
$Length = 7;

// get environment
$query_string = getenv( "QUERY_STRING");

// parse environment
// split query-string
$env_array = split( "&", $query_string);

// split in key=value and convert %XX
while (list($key, $val) = each($env_array))
{
// split
list($name, $wert) = split( "=", $val);

// replace %XX by character
$name = urldecode($name);
$wert = urldecode($wert);

// write to $cgivars
$CGIVars[$name] = $wert;
}

// eventually replace the default-values by the given parameters
if ($CGIVars[ "BGColor"])
{
if (ereg( "([0-9]*) ([0-9]*) ([0-9]*)", $CGIVars[ "BGColor"], $tmp))
{
$BGColor[ "red"] = $tmp[1];
$BGColor[ "green"] = $tmp[2];
$BGColor[ "blue"] = $tmp[3];
}
else if (eregi( "transparent", $CGIVars[ "BGColor"]))
{
$BGTrans = True;
}
else
{
$BGColor = GetColor($CGIVars[ "BGColor"]);
}
}

if ($CGIVars[ "FGColor"])
{
if (ereg( "([0-9]*) ([0-9]*) ([0-9]*)", $CGIVars[ "FGColor"], $tmp))
{
$FGColor[ "red"] = $tmp[1];
$FGColor[ "green"] = $tmp[2];
$FGColor[ "blue"] = $tmp[3];
}
else if (eregi( "transparent", $CGIVars[ "FGColor"]))
{
$FGTrans = True;
}
else
{
$FGColor = GetColor($CGIVars[ "FGColor"]);
}
}

if ($CGIVars[ "Length"])
{
$Length = $CGIVars[ "Length"];
}

// calculate size of image
$SizeX = $Length * 13;
$SizeY = 16;

// read counter-file
if (file_exists( "counter.txt"))
{
$fp = fopen( "counter.txt", "rt");
while ($Line = fgets($fp, 999))
{
// split lines into identifier/counter
if (ereg( "([^ ]*) *([0-9]*)", $Line, $tmp))
{
$CArr[ "$tmp[1]"] = $tmp[2];
}
}

// close file
fclose($fp);

// get counter
$Counter = $CArr[$CGIVars[ "Identifier"]];
$Counter += 1;
$CArr[$CGIVars[ "Identifier"]] = $Counter;
}
else
{
// the new counter is initialized with 1
$CArr[$CGIVars[ "Identifier"]] = 1;
$Counter = 1;
}

// write counter file
$fp = fopen( "counter.txt", "wt");

// output array elements
reset($CArr);
while (list($Key, $Value) = each($CArr))
{
$tmp = sprintf( "%s %d\n", $Key, $Value);
fwrite($fp, $tmp);
}

// close file
fclose($fp);

// Counter mit führenden Nullen auffüllen
// fill counter with leading 0´s
$Counter = sprintf( "%0".$Length. "d", $Counter);

// create image
$img = ImageCreate($SizeX + 4, $SizeY + 4);

// use interlace
ImageInterlace($img, 1);

// transparent color for separators
$trans = ImageColorAllocate($img, 1, 1, 1);
ImageColorTransparent($img, $trans);

// fill background
if ($BGTrans)
{
ImageFill($img, 1, 1, $trans);
}
else
{
$col = ImageColorAllocate($img, $BGColor[ "red"], $BGColor[ "green"],
$BGColor[ "blue"]);
ImageFill($img, 1, 1, $col);
}

// output digits
if ($FGTrans)
{
$col = $trans;
}
else
{
$col = ImageColorAllocate($img, $FGColor[ "red"], $FGColor[ "green"],
$FGColor[ "blue"]);
}

$PosX = 0;
for ($i = 1; $i <= strlen($Counter); $i++)
{
ImageString($img, $Font, $PosX + 3, 2 + $i % 2,
substr($Counter, $i - 1, 1), $col);

if ($i != 1)
{
// draw separator
ImageLine($img, $PosX, 0, $PosX, $SizeY + 4, $trans);
}

$PosX += 13;
}

// output image
ImageGif($img);
ImageDestroy($img);
?>



This is a script that list all image files on a given directory, and displays the thumbnails nicely formated within an HTML table. It also make use of JavScript to open pop up windows when the users want to see the full photo.
Categories : Graphics, PHP, Complete Programs, Java Script
This is a simple photo gallery that reads the image files from multiple directories, and generates a web page styled with CSS1. It opens single auto window to view and print a given image.
Categories : Graphics, Filesystem, PHP, Complete Programs
Automatic banner rotation. Randomly selects a banner for display.
Categories : Graphics, PHP, Complete Programs
DirtSearch Version 3.5 full function robust PHP and MySQL (and other databases) Site or Web Wide Search Engine
Categories : PHP, MySQL, Complete Programs, Search, Databases
PHPLinkRot v1.0 - program which allows users to report broken links on your website just by clicking a button. Works well on custom 404 pages
Categories : PHP, Complete Programs, Debugging, URLs, Site Planning
Functions to access a NNTP/NNRP newsserver. Complete set with examples is at ftp://ftp.nederland.net/pub/nnrplib
Categories : Search, PHP, Complete Programs
Upload images restricted by pixel size (Picture width and Picture Height)
Categories : PHP, HTML and PHP, Graphics
phpEasyMail: An easy way to send data from HTML-forms via EMail.
Categories : Email, HTML and PHP, Complete Programs, PHP
Web Self Service Resource Scheduler Using php3 and MySQL
Categories : PHP, Complete Programs, MySQL
PHP Email image generator - hide your email from bots - using the GD Library
Categories : PHP, Graphics, GD image library, Beginner Guides
ClassFuncDoc - This script is a classes and functions documentation tool.
Categories : PHP, Classes and Objects, Documentation, PHP Classes, Complete Programs
A set of functions sitting on top of the abstraction layer that makes it a little easier to do SQL stuff. Documentation is within
Categories : Databases, ODBC, Complete Programs, PHP
Read DPI value from image with PHP
Categories : PHP, Graphics, Filesystem
PHP Domain Availability Checker
Categories : PHP, Complete Programs, Regexps, HTTP, Sockets
Complete NotePad application for Websites (Like Yahoo Notepad)
Categories : PHP, Web Applications, Filesystem, Java Script, Complete Programs
 Supreme Creature wrote : 159
I can`t find this "gd-library" from anywhere, can anybody 
direct me to it? 
 
 Sjon wrote : 160
And where`s that colors.php script then...
Please provide me with an url or something...


Thanx, Sjon.
 
 Claus Radloff wrote : 202
The gd-library is part of the binary distributions of PHP (at least
under Windows). It will be built, when compiling the source
distribution, if you have installed the gdlib, which should be 
part of the most Linux distributions.

The Colors script is available here in the section graphics and
is titled `Definition of Colornames`

Regards

Claus
 
 mator wrote :268
where the $%^& workin` example?