AuthorMessage
ThomAce
n00b
Posts: 18

First easy hit counter 
Show how many wisits on your syte.
Create first the 2 folders. data and pics folder... place the counter.dat to the data folder and place the images to the pics folder. pics names: 0 - 10 and jpg or gif.
(if you use another type or name of images you need to modifie the code)
Code:

<?php
//============================================================================\\
//===                        Created by ThomAce                            ===\\
//============================================================================\\
$datfile = "data/counter.dat";
   
$fa = @fopen($datfile, "r") or die ("The file isn't readable!");     // open file and read one row
flock($fa, 1);
while(! feof($fa))
{
        $dat = chop(fgets($fa));
         }
flock($fa, 3);
fclose($fa);
$fa = @fopen($datfile, "r") or die ("The file isn't readable!");           // open the file and read chars to an array
flock($fa, 1);
while(! feof($fa))
{
   $char[] = chop(fgetc($fa));
        }
flock($fa, 3);
fclose($fa);
$fa = @fopen($datfile, "w") or die ("The file isn't writable!");             //write the count data + 1
flock($fa, 2);
   fwrite($fa, $dat + 1);
flock($fa, 3);
fclose($fa);
for ($ch = 0; $ch <= count($char); $ch++)         // for cycle is faster than while !
 {
         if(strlen($char[$ch]) == 1)                       // if chars lenght = 1 write it...
         {
           print "<img src=\"pics/" . $char[$ch] . ".jpg\">";
          }
         }
print "<!-- Created by ThomAce //-->";              // ;)
?>

ThomAce
n00b
Posts: 18

Simple socket client,  $Lock to $Key and reading the hub's messages. write to a file.
(easy code )
Code:

<?php
$output1 = "outdat.txt";
 $fa2 = fopen($output1, "w") or die ("Oohhh... shit! The file isn't writable!");
  fwrite($fa2, "");
  fclose($fa2);
set_time_limit(0);
error_reporting(E_ALL);
  $service_port = 411;                                 // not null !
  $address = "127.0.0.1";                             // not null !
  $nick = "PHP_SCRIPT";                              // not null !
//  $password = "mypass";                           // if u need it...
if (($socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0)
 {
  echo "socket_create() failed: reason: " . socket_strerror($socket) . "\n";
}
$result = socket_connect($socket, $address, $service_port);
if ($result < 0)
 {
   echo "socket_connect() failed.\nReason: ($result) " . socket_strerror($result) . "\n";
}
$lock_1 = socket_read($socket, 2048);
$lock1 = explode(" ", $lock_1);
 $_LOCK = $lock1[1];
function lock2key($_LOCK) {
   $lockLength = strlen ($_LOCK);
   $h = ord($_LOCK{0}) ^ ord( $_LOCK{ $lockLength - 1} ) ^ ord( $_LOCK{ $lockLength - 2} ) ^ 5;
    while ($h > 255) {$h = $h - 256;}
    $h = (($h<<4) & 240) | (($h>>4) & 15);
   $a = $h;
   if ($a == '126' or // '~'
       $a == '124' or // '|'
       $a == '96' or  // '`'
       $a == '36' or  // '$'
       $a == '5' or   // '^E'
       $a == '0')     // NUL
   {
     $LockToKey = "/%DCN";
     if ($a < 100)
       $LockToKey .="0";
     if ($a < 10)
       $LockToKey .="0";
      $LockToKey .= $a; // As a string integer
     $LockToKey .= "%/";
   } else {
     $LockToKey = chr ($a);  // No transformation.
   }
   for ($j = 1; $j < strlen($_LOCK); $j++) {
      $h = ord($_LOCK{$j}) ^ ord($_LOCK{$j-1});
   while ($h > 255) {$h = $h - 256;}
      $h = (($h<<4) & 240) | (($h>>4) & 15);
     $a = $h;
   if ($a == '126' or // '~'
       $a == '124' or // '|'
       $a == '96' or  // '`'
       $a == '36' or  // '$'
       $a == '5' or   // '^E'
       $a == '0')     // NUL
   {
     $LockToKey .= "/%DCN";
     if ($a < 100)
       $LockToKey .="0";
     if ($a < 10)
       $LockToKey .="0";
      $LockToKey .= $a; // As a string integer
     $LockToKey .= "%/";
   } else {
     $LockToKey .= chr ($a);  // No transformation.
   }
   }
   return $LockToKey;
}
//==============================================================================
 $be1 = "$" . "Supports UserCommand NoGetINFO NoHello UserIP2 TTHSearch GetZBlock |";
 $be2 = "$" . "Key " . lock2key($_LOCK) . "|";
 $be3 = "$" . "ValidateNick " . $nick . "|";
 $be5 = "$" . "Version 1,0091|";
 $be6 = "$" . "GetNickList|";
 $be7 = "$" . "MyINFO " . "$" . "ALL " . $nick . " PHP script by ThomAce<++ V:0.401,M:P,H:0/0/1,S:1>". "$ " . "$" . "DSL" . "$" . "webmaster@thomace.myip.hu". "$" . "2187508559" . "$" . "|";
//==============================================================================
 socket_write($socket, $be1, strlen($be1));
  socket_write($socket, $be2, strlen($be2));
   socket_write($socket, $be3, strlen($be3));
   if( isset($password))
   {
   switch(password)
   {
   case(strlen($_POST['pass']) > 2):
      $be4 = "$" . "MyPass " . $_POST['pass'] ."|";
      socket_write($socket, $be4, strlen($be4));
      break;
   case(strlen($_POST['pass']) < 2):
   break;
      }
            }
     socket_write($socket, $be5, strlen($be5));
      socket_write($socket, $be6, strlen($be6));
       socket_write($socket, $be7, strlen($be7));
//==============================================================================
for($i = 0; true; $i++)                  // unstopable cycle ! ! !
{
 $buf1 = socket_read($socket, 10240, PHP_BINARY_READ) . "\n";
    if(strlen($buf1) > 1)
    {
  $fa = fopen($output1, "a") or die ("VATA FAK!");
          flock($fa, 2);
                  fputs($fa, $buf1);
          flock($fa, 3);
          fclose($fa);
          }
 }
 socket_close($socket);
 die;
?>

ThomAce
n00b
Posts: 18

This is the 2nd hitcounter. use cookies and a "little" easy code.
Any questions u have, just take it.
Code:

<?php
//============================================================================\\
//===                        Created by ThomAce                            ===\\
//===  Creation date: 2005-09-19.  Created under 5 minutes   :D            ===\\
//============================================================================\\
$dat1 = @file("data/counter.dat") or die ("I can't read the file");             //data file and location.
$dat = $dat1[0];                                                                //select the 0 array.
for($i = 0; $i <= strlen($dat); $i++)
{
  $sz = $i + 1;
        if(strlen(substr($dat, $i, $sz)) == 1)
          {
           print "<img src=\"pics/" . substr($dat, $i, $sz) . ".jpg\">";
                }
            }
if (! isset($_COOKIE["visitor"]))                                               //if visitor variable doesn't exist
{
setcookie("visitor", "1", time()+3200*24, "/", "yourdomain.com", 0);            //set time to 24 hours and the domain.
$fa = @fopen("data/counter.dat", "w") or die ("Can't write to the file!");
  flock($fa, 2);
    fwrite($fa, $dat + 1);
  flock($fa, 3);
  fclose($fa);
               }
?>

Mickey
Ametuar
Posts: 115

Cool scripts for PHP programmers hmm, I advice you to post them in separated topics since they are different, so users can post quuestions/comments to each of them.
ThomAce
n00b
Posts: 18

Quoted from Mickey
Cool scripts for PHP programmers hmm, I advice you to post them in separated topics since they are different, so users can post quuestions/comments to each of them.

Thank you Mickey! 
Nice things 
but i have few code (every code is my) and that number is more than 10...
Just open more than 10 topci for just one post ?  :roll:
Mickey
Ametuar
Posts: 115

Quoted from ThomAce
Thank you Mickey! 
Nice things 
but i have few code (every code is my) and that number is more than 10...
Just open more than 10 topci for just one post ?  :roll:

Of course so that users can post comments questions praises to each of them.
Meka][Meka
Unstopable
Posts: 700

Quoted from Mickey
Quoted from ThomAce
Thank you Mickey! 
Nice things 
but i have few code (every code is my) and that number is more than 10...
Just open more than 10 topci for just one post ?  :roll:

Of course so that users can post comments questions praises to each of them.

indeed, mickey is very right...