ik zien het ni ze :S
Geplaatst: 01 jun 2003, 13:58
hallo,
ik ontvan twee foutmeldingen van php
dit is counter.php
de code in index.php
tis te warm om helder te denken
ik ontvan twee foutmeldingen van php
Parse error: parse error, unexpected T_INC, expecting ')' in **********/httpdocs/counter.php on line 46
Fatal error: Cannot instantiate non-existent class: counter in ******/httpdocs/index.php on line 230
dit is counter.php
Code: Selecteer alles
<?php
class Counter {
var $config=array();
function Counter(){
//url to images
$this->config['img']="http://www.delphiprogramming.be/images/digits/";
//url to animated images
$this->config['animated_img']="http://www.delphiprogramming.be/images/digits_ani/";
//number of digits to show
$this->config['pad']=6;
//images sizes
$this->config['width']=16;
$this->config['height']=22;
//wanna block ip addresses ?
$this->config['block_ip']=false;
//path to logfile
$this->config['logfile']="./ip.txt";
$this->config['block_time']=15;
}
function is_new_visitor() {
$is_new=true;
$rows=@file($this->config['logfile']);
$this_time=time();
$ip=$_SERVER['REMOTE_ADDR'];
$reload_dat= fopen($this->config['logfile'],"wb");
flock($reload_dat,2);
for ($i=0; $i<sizeof($rows); $i++) {
list($time_stamp,$ip_addr) = split ("\|",$rows[i]);
if($this_time < ($time_stamp + $this->config['block_time'])){
if(chop($ip_addr) == $ip ){
$is_new=false;
}else{
fwrite($reload_dat,"$time_stamp|$ip_addr");
}
}
}
fwrite($reload_dat,"$this_time|$ip\n");
flock($reload_dat,3);
fclose($reload_dat);
return $is_new;
}
function read_counter_file($page) {
$update=false;
if(!file_exists("./pages/$page.txt")){
$count_dat=fopen(" ./pages/$page.txt","w+");
$this->counter=1;
fwrite($count_dat,$this->counter);
fclose($count_dat);
}else{
$fp = fopen (" ./pages/$page.txt","r+");
flock($fp,2);
$this->counter = fgets($fp,4096);
flock($fp,3);
fclose($fp);
if($this->config['block_ip']){
if($this->is_new_visitor()){
$this->counter++;
$update=true;
}
}else{
$this->counter++;
$update=true;
}
if($update){
$fp = fopen (" ./pages/$page.txt","r+");
flock($fp,2);
rewind($fp);
fwrite($fp,$this->counter);
flock,$fp,3);
fclose($fp);
}
}
return $this->counter;
}
function create_output($page=''){
if(empty($page)) {
$page="counter";
}
$this->read_counter_file($page);
$this->counter=sprintf("%0"."".$this->config['pad'].""."d",$this->counter);
$ani_digits = sprintf("%0"."".$this->config['pad'].""."d",$this->counter+1);
$html_output="<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr align=\"center\">\n";
for($i=0; $1 < strlen($this->counter); $i++) {
if(substr("$this->counter",$i,1) == substr("$ani_digits",$1,1)){
$digit_pos=substr("$this-counter",$i,1);
$html_output .="<td><img src=\"".$this->config['img']."$digit_pos.gif\"";
}else{
$digit_pos = substr("$ani_digits",$i,1);
$html_output .="<td><img src=\"".$this->config['animated_img']."$digit_pos.gif\"";
}
$html_output .=" width=\"".$this->config['width']."\" height=\"".$this->config['height']."\"></td>\n";
}
$html_output .="</tr></table>\n";
return $html_output;
}
}
?>
de code in index.php
Code: Selecteer alles
<?php
include_once "./counter.php";
$ani_counter = new Counter();
$ani-counter->create_output("index.php");
?>
tis te warm om helder te denken