home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / php.exe / Counter1.php < prev    next >
Encoding:
Text File  |  2001-07-02  |  5.7 KB  |  220 lines

  1.     //**************************************
  2.     //     
  3.     // Name: Counter.php
  4.     // Description:a little counter-script f
  5.     //     or PHP. Needs the gd-library and Colors.
  6.     //     php by Claus Radloff
  7.     // By: PHP Code Exchange
  8.     //**************************************
  9.     //     
  10.     
  11.     <?
  12.     ////////////////////////////////////////
  13.     /////////////////////////////////
  14.     //
  15.     // counter.php - implements a simple Cou
  16.     //     nter
  17.     // 
  18.     // Author: Claus Radloff
  19.     // 
  20.     // Description:
  21.     // The counter in this file can count mu
  22.     //     ltiple counters. Therefore
  23.     // every counter gets it┤s own identifie
  24.     //     r.
  25.     // The Fore- and Backgroundcolor and the
  26.     //     number of digits are
  27.     // defined, but can be overwritten. Fore
  28.     //     - and Backgroundcolor may
  29.     // be transparent as well.
  30.     // The Parameters are passed in the URL.
  31.     //     
  32.     // Some Examples:
  33.     // simple counter:
  34.     //<img src="counter.php?Identifier=Te
  35.     //     st">
  36.     //
  37.     // Counter with red background
  38.     //<img src="counter.php?Identifier=Te
  39.     //     st&BGColor=255+0+0">
  40.     // or:
  41.     //<img src="counter.php?Identifier=Te
  42.     //     st&BGColor=red">
  43.     //
  44.     // Counter with red background, green fo
  45.     //     reground and 4 digits
  46.     //<img src="counter.php?Identifier=Te
  47.     //     st&BGColor=255+0+0&FGColor=0+255+0&Lengt
  48.     //     h=4">
  49.     // or:
  50.     //<img src="counter.php?Identifier=Te
  51.     //     st&BGColor=red&FGColor=green&Length=4"&g
  52.     //     t;
  53.     //
  54.     // Counter with transparent background a
  55.     //     nd red foreground
  56.     //<img src="counter.php?Identifier=Te
  57.     //     st&BGColor=transparent&FGColor=red">
  58.     // 
  59.     Header("Content-type: image/gif");
  60.     require("colors.php");
  61.     // Load the gd-library
  62.     // under Windooze use this one
  63.     // dl("php3_gd.dll");
  64.     // under UNIX use this one
  65.     dl("php3_gd.so");
  66.     // some default-values
  67.     $Font = 5;
  68.     $BGColor = GetColor("black");
  69.     $BGTrans = False;
  70.     $FGColor = GetColor("white");
  71.     $FGTrans = False;
  72.     $Length= 7;
  73.     // get environment
  74.     $query_string = getenv("QUERY_STRING");
  75.     // parse environment
  76.     // split query-string
  77.     $env_array = split("&", $query_string);
  78.     // split in key=value and convert %XX
  79.     while (list($key, $val) = each($env_array))
  80.     {
  81.     // split
  82.     list($name, $wert) = split("=", $val);
  83.     // replace %XX by character
  84.     $name = urldecode($name);
  85.     $wert = urldecode($wert);
  86.     // write to $cgivars
  87.     $CGIVars[$name] = $wert;
  88.     }
  89.     // eventually replace the default-values
  90.     //     by the given parameters
  91.     if ($CGIVars["BGColor"])
  92.     {
  93.     if (ereg("([0-9]*) ([0-9]*) ([0-9]*)", $CGIVars["BGColor"], $tmp))
  94.     {
  95.     $BGColor["red"]= $tmp[1];
  96.     $BGColor["green"] = $tmp[2];
  97.     $BGColor["blue"] = $tmp[3];
  98.     }
  99.     else if (eregi("transparent", $CGIVars["BGColor"]))
  100.     {
  101.     $BGTrans = True;
  102.     }
  103.     else
  104.     {
  105.     $BGColor = GetColor($CGIVars["BGColor"]);
  106.     }
  107.     }
  108.     if ($CGIVars["FGColor"])
  109.     {
  110.     if (ereg("([0-9]*) ([0-9]*) ([0-9]*)", $CGIVars["FGColor"], $tmp))
  111.     {
  112.     $FGColor["red"]= $tmp[1];
  113.     $FGColor["green"] = $tmp[2];
  114.     $FGColor["blue"] = $tmp[3];
  115.     }
  116.     else if (eregi("transparent", $CGIVars["FGColor"]))
  117.     {
  118.     $FGTrans = True;
  119.     }
  120.     else
  121.     {
  122.     $FGColor = GetColor($CGIVars["FGColor"]);
  123.     }
  124.     }
  125.     if ($CGIVars["Length"])
  126.     {
  127.     $Length = $CGIVars["Length"];
  128.     }
  129.     // calculate size of image
  130.     $SizeX = $Length * 13;
  131.     $SizeY = 16;
  132.     // read counter-file
  133.     if (file_exists("counter.txt"))
  134.     {
  135.     $fp = fopen("counter.txt", "rt");
  136.     while ($Line = fgets($fp, 999))
  137.     {
  138.     // split lines into identifier/counter
  139.     if (ereg("([^ ]*) *([0-9]*)", $Line, $tmp))
  140.     {
  141.     $CArr["$tmp[1]"] = $tmp[2];
  142.     }
  143.     }
  144.     // close file
  145.     fclose($fp);
  146.     // get counter
  147.     $Counter = $CArr[$CGIVars["Identifier"]];
  148.     $Counter += 1;
  149.     $CArr[$CGIVars["Identifier"]] = $Counter;
  150.     }
  151.     else
  152.     {
  153.     // the new counter is initialized with 1
  154.     //     
  155.     $CArr[$CGIVars["Identifier"]] = 1;
  156.     $Counter = 1;
  157.     }
  158.     // write counter file
  159.     $fp = fopen("counter.txt", "wt");
  160.     // output array elements
  161.     reset($CArr);
  162.     while (list($Key, $Value) = each($CArr))
  163.     {
  164.     $tmp = sprintf("%s %d\n", $Key, $Value);
  165.     fwrite($fp, $tmp);
  166.     }
  167.     // close file
  168.     fclose($fp);
  169.     // Counter mit fⁿhrenden Nullen auffⁿlle
  170.     //     n
  171.     // fill counter with leading 0┤s
  172.     $Counter = sprintf("%0".$Length."d", $Counter);
  173.     // create image
  174.     $img = ImageCreate($SizeX + 4, $SizeY + 4);
  175.     // use interlace
  176.     ImageInterlace($img, 1);
  177.     // transparent color for separators
  178.     $trans = ImageColorAllocate($img, 1, 1, 1);
  179.     ImageColorTransparent($img, $trans);
  180.     // fill background
  181.     if ($BGTrans)
  182.     {
  183.     ImageFill($img, 1, 1, $trans);
  184.     }
  185.     else
  186.     {
  187.     $col = ImageColorAllocate($img, $BGColor["red"], $BGColor["green"],
  188.     $BGColor["blue"]);
  189.     ImageFill($img, 1, 1, $col);
  190.     }
  191.     // output digits
  192.     if ($FGTrans)
  193.     {
  194.     $col = $trans;
  195.     }
  196.     else
  197.     {
  198.     $col = ImageColorAllocate($img, $FGColor["red"], $FGColor["green"],
  199.     $FGColor["blue"]);
  200.     }
  201.     $PosX = 0;
  202.     for ($i = 1; $i <= strlen($Counter); $i++)
  203.     {
  204.     ImageString($img, $Font, $PosX + 3, 2 + $i % 2, 
  205.             substr($Counter, $i - 1, 1), $col);
  206.         
  207.         if ($i != 1)
  208.         {
  209.         // draw separator
  210.         ImageLine($img, $PosX, 0, $PosX, $SizeY + 4, $trans);
  211.         }
  212.         
  213.         $PosX += 13;
  214.     }
  215.     // output image
  216.     ImageGif($img);
  217.     ImageDestroy($img);
  218.     ?>
  219.  
  220.