bezoekersteller-met-image

Gesponsorde koppelingen

PHP script bestanden

  1. bezoekersteller-met-image

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
session_start();
ob_start();

################################################################################
#
#    This file contains al the functions
#              Marcel Boersma
#
################################################################################


    class teller{
        function
connect($username, $password, $host, $db){//function connect to db
                mysql_connect($host, $username, $password) OR die("There was no connection to the db");//connect to the host
                mysql_select_db($db) OR die("Couldn't connect to database....");//connect to the database
        }

        function
check_table(){//open function
            //get table list

            $tables=mysql_query("SHOW TABLES");//get tables
            $counted=mysql_num_rows($tables);//count tables
            if($counted != 0){//check if counted isn't zero
                for($x=0;$x<=$counted-1;$x++){//for each result load result into array
                    $table[$x]=mysql_result($tables,$x);//load in array
                }
            }

    
            $table_array="teller";//table name
            if(!in_array($table_array,$table)){//check if exists
                $this->create_table("teller");
            }
        }
//close function



    private function create_table($table_name){
            switch($table_name){//switch table name
                case 'teller' :    $table_data="CREATE TABLE `teller` (
                                 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
                                 `ip` VARCHAR( 32 ) NOT NULL ,
                                 `date` INT NOT NULL
                                 ) TYPE = MYISAM ;"
;//create data
                        mysql_query($table_data);//create table
                        $this->check_table;//check again
                break;
            }

        }

        function
user_add(){
            $ip=$_SERVER['REMOTE_ADDR'];//get ip address
            if(!isset($_SESSION['ip'])){//check if session exsists
                $_SESSION['ip']=$ip;//make session
                $date=$this->make_date();//make date
                mysql_query("INSERT INTO teller (`ip`, `date`) VALUES ('$ip', '$date')");//insert into the database

            }
        }

        function
make_date(){
            //set date
            $month=date("n");//set month
            $day=date("j");//set day
            $year=date("Y");//set year

            $date_now=mktime(0, 0, 0, $month, $day, $year);//make timestamp


        return $date_now;//return timestamp
        }

        function
color($color, $index){
            if(strlen($color) != 6){//if color hasn't 6 chars, color is white
                $color='FFFFFF';
            }

            switch($index){//switch index
                case '1' : $splited=substr($color, 0, 2);// index = 1 return the first heximals
                break;
                case
'2' : $splited=substr($color, 2, 4);//index = 2 return the second heximals
                break;
                case
'3' : $splited=substr($color, 4, 6);//index = 3 return the third heximals
                break;
            }

            $color=hexdec($splited);//get heximals
            return $color;//return heximals
        }

        function
picture($month, $year, $x, $y, $color_background, $color_line, $line){
            //background colors
            $color_background1=$this->color($color_background, 1);
            $color_background2=$this->color($color_background, 2);
            $color_background3=$this->color($color_background, 3);
            
            //indexline colors
            $color_line1=$this->color($color_line, 1);
            $color_line2=$this->color($color_line, 2);
            $color_line3=$this->color($color_line, 3);
            
            //line color
            $line1=$this->color($line, 1);
            $line2=$this->color($line, 2);
            $line3=$this->color($line, 3);


            header("Content-type: image/png");//set header
            $im = @imagecreate($x, $y)//create image
               

            $background=imagecolorallocate($im,$color_background1 , $color_background2, $color_background3);//set background
            $indexline=imagecolorallocate($im, $color_line1, $color_line2, $color_line3);//set indexline color
            $line=imagecolorallocate($im, $line1, $line2, $line3);//set line color

            $numbersofindexline=$y/20;//count index lines
            for($a=0;$a<$numbersofindexline;$a++){
                $ya=$a*20;//heigth of index line
                imageline($im, '0', $ya, '500', $ya, $indexline);//$im=image, x1, y1, x2, y2, color
                imagestring($im, 100, 5, $ya-2,  $y-$ya, $indexline);//index number
            }
            //load visitors out of db for this month
                switch($month){//switch month type
                case '' : $plus=0;//if type is empty mont=0
                break;
                default :
if(ctype_digit($month) AND $month <= 12){ $month=$month; }else{ $month=0; }//if type isn't empty and is a number plus is okay, else month = 0
                break;

            }

                 //print month name
                $monthname=date("F");
                imagestring($im, 35, $x-50, $y-($y-25), $monthname, $line);


            $visitors=array();//make array for visitors
            $counted_days_in_month=date('t');//count days in month
            for($a=0 ; $a <= $counted_days_in_month; $a++){
                    $date=mktime(0, 0, 0, date('n')+$month, date('j')+$a , date('Y')+$year);//begin time
                    $qry_count=mysql_query("SELECT * FROM `teller` WHERE date='$date'");//count for each day visitors
                    $counted=mysql_num_rows($qry_count);
                    $visitors[$a]=$counted;//put visitors into array
            }
            
            $inarray=$counted; //values in array is simulair to the counted days
            for($i=0;$i<$inarray-1;$i++){
                $x_1=$i*($x/$inarray);//x divide counted days
                $y_1=$y-$visitors[$i];//counted visitors day one
                $x_2=$x_1+($x/$inarray);//draw line to
                $y_2=$y-$visitors[$i+1];//counted visitors next day
                
                imageline($im, $x_1, $y_1, $x_2, $y_2, $line);//dray line
                imagestring($im, 100, $x_2, $y_2, $visitors[$i+1], $line);//set numbers

            }
            imagepng($im);
            imagedestroy($im);

        }

    }



?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.