WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

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 : 21838
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  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 its 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 fhrenden Nullen auffllen
// fill counter with leading 0s
$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);
?>



Automatic banner rotation. Randomly selects a banner for display.
Categories : Graphics, PHP, Complete Programs
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
GoTemplate
Categories : PHP, Complete Programs, Templates
CAPTCHA[Image verification]
Categories : PHP, Security, GD image library, Graphics, Sessions
Web Self Service Resource Scheduler Using php3 and MySQL
Categories : PHP, Complete Programs, MySQL
Look for the *position* of the first occurence of string2 in string1, beginning at position start.
Categories : Complete Programs, PHP, Strings
Simple Mini Poll class library (SimPoll)
Categories : PHP, PHP Classes, Databases, MySQL, Complete Programs
phpRecommend v1.2 - UPDATED - recommend this page to a friend script - VERY easy install - now with data logging to text file
Categories : Complete Programs, PHP, Link to Article, URLs, Misc
A PHP based webmail at : http://www.horde.org/imp
Categories : Email, IMAP, PHP, Complete Programs
A couple of functions that convert an IP address into its color code and not-color-code. Useful when viewing an apache log with a mysql result grouped by IP
Categories : PHP, Graphics, Databases
How to display any array in several rows and columns of a table. Not just in one column or in alternate rows. This example shows a nice color table generated with PHP, but can be used with any array values(e.g. Database)
Categories : Arrays, PHP, Miscellaneous, Beginner Guides, Graphics
QTO File Manager
Categories : Filesystem, filePro, Complete Programs, PHP, Content Management
HTML_Graphs uses PHP to provide a consistent interface for creating HTML based charts. The user of the class sets up arrays that are passed to html_graph() which then takes care of all the messy HTML layout.
Categories : Graphics, Arrays, PHP, PHP Classes, Charts and Graphs
This script will read all images from a folder and read the files into an array. It uses rand() to get a random number. It will display a random image from the image folder given.
Categories : PHP, Arrays, Graphics, Filesystem
 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?