gd-library-bezoekers-teller-grafisch

Gesponsorde koppelingen

PHP script bestanden

  1. gd-library-bezoekers-teller-grafisch

« 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?php
################################################################################
#     *  Name: Josko de Boer                                                   #
#     *  E-mail: [email protected]                                         #
#     *  country: The Netherlands                                              #
#     *  company: ZcHosting                                                    #
#     *  language: Php + Mysql                                                 #
#     *  using gd libaries                                                     #
################################################################################

function QArrayRGB($Col)
{

      $result = array();
      $result[] = hexdec($Col{1}.$Col{2});
      $result[] = hexdec($Col{3}.$Col{4});
      $result[] = hexdec($Col{5}.$Col{6});
      return $result;
}

//---- function for getting heights  ---//
function Height($number, $max, $xCall)
{


      //-- count visits ---//
      $x = $number;
      //-- people each px -- //
      
      $Px = $max / $xCall;
      //--- height ---//
      $H = $x / $Px;
      
      return round($H, 0);
}

//---- the class for the counter ---------//
class QCounter
{
      //---- database vars ---------//
      var $host;
      var
$user;
      var
$password;
      var
$db;
      //---- current date, timestamp on 12:00:00 ---------//
      var $date;
      //---- sizes ---------//
      var $x;
      var
$y;
      //---- Colors ---------//
      var $bgcolor;
      var
$fontcolor;
      var
$linecolor;
      var
$commentcolor;
      var
$indexcolor;
      //---- constructor ---------//
      function __construct()
      {

            if(func_num_args() == 0) exit("You <b> must</b> give a load of vars for this.<br \>\n You still are to do that.");
            //---- autoloading some static vars ---------//
            $this->host     = func_get_arg(0);
            $this->user     = func_get_arg(1);
            $this->password = func_get_arg(2);
            $this->db       = func_get_arg(3);
            
            $this->date = mktime(
                        0,
                        0,
                        0,
                        date("m"),
                        date("d"),
                        date("y")
            );

            

            $this->bgcolor      = func_get_arg(4);
            $this->fontcolor    = func_get_arg(5);
            $this->linecolor    = func_get_arg(6);
            $this->commentcolor = func_get_arg(7);
            $this->indexcolor   = func_get_arg(8);
            
            $this->bgcolor      = QArrayRGB( $this->bgcolor);
            $this->fontcolor    = QArrayRGB( $this->fontcolor);
            $this->linecolor    = QArrayRGB( $this->linecolor);
            $this->commentcolor = QArrayRGB( $this->commentcolor);
            $this->indexcolor   = QArrayRGB( $this->indexcolor);
            

            $this->x = func_get_arg(9);
            $this->y   = func_get_arg(10);
            
            //---- calling functions ----------//
            $this->__connect();
            $Verification = $this->__logger();
            if( $Verification)
            {

                  $this->__image();
            }
      
      }

      //---- connection ---------//
      function __connect()
      {

            mysql_connect($this->host, $this->user, $this->password) or die(mysql_error());
            mysql_select_db($this->db)         or die(mysql_error());
      }

      //---- add record ---------//
      function __logger()
      {

            $ip = $_SERVER['REMOTE_ADDR'];
            
            $sql = "SELECT * FROM count WHERE time='".$this->date."' AND ip='".$ip."'";

            $query = mysql_query($sql) or die(mysql_error());

            $result = mysql_num_rows($query);

            if($result == 0)
            {


                  $sql = "INSERT INTO count (time, ip) VALUES ('".$this->date."', '".$ip."')";
                  mysql_query($sql) or die(mysql_error());
                  return false;
            }

            else
            {
                  return true;
            }
      }

      //----- This is the main function, giving the image ---- //
      function __image()
      {

            $ImagePng = imagecreate($this->x, $this->y);
            $error = false;

            //--- allocating colors -----//

            $this->bgcolor      = imagecolorallocate(
                                    $ImagePng,
                                    $this->bgcolor[0],
                                    $this->bgcolor[1],
                                    $this->bgcolor[2]
                                    );


            $this->fontcolor    = imagecolorallocate(
                                    $ImagePng,
                                    $this->fontcolor[0],
                                    $this->fontcolor[1],
                                    $this->fontcolor[2]
                                    );

            
            $this->linecolor    = imagecolorallocate(
                                    $ImagePng,
                                    $this->linecolor[0],
                                    $this->linecolor[1],
                                    $this->linecolor[2]
                                    );

            
            $this->commentcolor = imagecolorallocate(
                                    $ImagePng,
                                    $this->commentcolor[0],
                                    $this->commentcolor[1],
                                    $this->commentcolor[2]
                                    );

            
            $this->indexcolor   = imagecolorallocate(
                                    $ImagePng,
                                    $this->indexcolor[0],
                                    $this->indexcolor[1],
                                    $this->indexcolor[2]
                                    );

            if($_GET['tryout'] == "true")
            {

                  $max = rand( 100, 10000);
                  $logs = array(
                        rand(10, $max),
                        rand(10, $max),
                        rand(10, $max),
                        rand(10, $max),
                        rand(10, $max),
                        rand(10, $max),
                        rand(10, $max)
                        );
            }

            else
            {
                  $logs = $this->__load();
            }

            
            $xCall = ($this->x-50) / count($logs);
            
            $yCall = ($this->y-50);
            
            $PeopleStripe = max($logs) / 20;

            $yStripe = $yCall / 20;
            
            $xStripe = 5;
            

            
            for($a = 0; $a <= 20; $a++)
            {

                  $cury = $a * $yStripe + 45;
                  imageline($ImagePng, 5, $cury, 5+$xStripe, $cury, $this->indexcolor);

                  $number = (20*$PeopleStripe)-($a*$PeopleStripe);

                  imagestring($ImagePng, 100, 15, $cury-5, round($number, 0), $this->commentcolor);
            }

            
            imageline($ImagePng, 50, 0, 50, $this->y, $this->indexcolor);
            
            $iterance = 0;
            foreach($logs AS $visit)
            {


                  $iterance++;

                  $xCur = 55 + ( $iterance - 1) * $xCall;



                  //--- drawing line ---//

                  $yCur = $this->y - Height($visit, max($logs), $yCall);

                  $yNext = $this->y - Height($logs[$iterance], max($logs), $yCall);

                  $xNext = $xCur + $xCall;

                if($iterance != 7)
                        imageline($ImagePng, $xCur, $yCur, $xNext, $yNext, $this->linecolor);
                 //----- text -----/

                        imagestring($ImagePng, 100, $xCur, 15, $visit, $this->fontcolor);
                        imagestring($ImagePng, 100, $xCur, 35, $iterance, $this->fontcolor);
            }


            header("Content-type: image/png");
            imagepng($ImagePng);
            imagedestroy($ImagePng);

      
      }
      function
__load()
      {

            $array = array();
            for($a = 0; $a < 7; $a++)
            {

                  $ddate = $this->date;
                  $ddate -= $a * 60 * 60 * 24;
                  $query = mysql_query("SELECT * FROM count WHERE time='".$ddate."'") or die(mysql_error());
                  $array[] = mysql_num_rows($query);
            }


            return $array;
      }
}

?>

 
 

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.