Login   Register  
PHP Classes
elePHPant
Icontem

File: redir.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Roberto Bertó  >  SimpleDB  >  redir.php  >  Download  
File: redir.php
Role: Example script
Content type: text/plain
Description: A simple counter and stats using the SimpleDB
Class: SimpleDB
Store and read arrays from file based databases
Author: By
Last change:
Date: 13 years ago
Size: 1,327 bytes
 

Contents

Class file image Download
<?PHP

/*

Example of a internal counter with stats

TEST STEP 1
-- create the database and increments the counter
redir.php?url=index.html - will redir index.html, add +1 to counter
redir.php?url=http://www.altavista.com - will open altavista, add +1 to the counter

TEST STEP 2
-- view the stats
redir.php?stats=password

*/

if (!empty($url) || !empty($stats)) {
    
// set to 0 if running under windows
    
$config[lockfiles]            = 1;
    
// the password
    
$config[password]            = "password";
    
// the file will be save
    
$config[database]    = 'redir.dat';
    
// the SimpleDB
    
include_once ("db.php");


    
$SimpleDB = new SimpleDB;
    
$SimpleDB->filename $config[database];
    
$SimpleDB->lockfiles $config[lockfiles];

    
$db $SimpleDB->db_get();

    
// If the DB open continue

    
if ($db !== FALSE) {
        if (!empty(
$url)) {
            
//increse counter
            
$db[$url]++;
            
//write db
            
$write $SimpleDB->db_write($db);
            
//redirect
            
header("Location: $url");
        }
        
// the stats part
        
elseif ($stats == $config[password]) {
            
reset($db);
            
asort($db);
            
$db array_reverse($db);
            print 
"<table border=1>";
            while (list(
$a,$b) = each($db)) {
                print 
"<tr><td>$a</td><td>$b</td></tr>\n";
            }
            print 
"</table>";
        }
    }
    else {
        print 
"Cant Open the Database";
        exit;
    }
}

?>