php - Visitor CAPTCHA Image Has An Error Revolving Around "fopen", "fputs" & "fclose" -


i've made simple captcha displays total number of visitors of website using 4 files: counter.php, counter.png, counter.txt, , visitor-ip.txt. counter.txt file keeps total number of visitors (1, 2, 10, 20, 140, etc). visitor-ip.txt file keeps track of of visitor's ip address, if return won't counted again. counter.php writes total number of visitors counter.png file. last night every thing worked. won't. 3-4 errors , when check indicated lines, seems normals. errors seems revolve around fopen, fputs, fclose.

errors

warning: fopen(visitor-ip.txt): failed open stream: permission denied in /users/matthew/sites/counter/counter-1/counter.php on line 24 warning: fputs() expects parameter 1 resource, boolean given in /users/matthew/sites/counter/counter-1/counter.php on line 30 warning: fclose() expects parameter 1 resource, boolean given in /users/matthew/sites/counter/counter-1/counter.php on on line 31 fatal error: call undefined function createcounterimage() in /users/matthew/sites/counter/counter-1/counter.php on on line 44 

php "counter.php"

<?php  $counter = "counter.txt";  $visitorips = "visitor-ip.txt";  $ipaddress = $_server ["remote_addr"];  $currenttime = time ();   // 1 hour = 3,600 seconds  $ipresidenttime = 7200;  $ips = array ();  $ipfamily = fopen ($visitorips, "r");  $flags = 0;  while (!feof ($ipfamily)) {   $line = fgets ($ipfamily);   if (preg_match ("/\d/", $line)) {    $slack = split (";", $line);    $ip = $slack [0];    $time = trim ($slack [1]);    if ($time > $currenttime - $ipresidenttime) {     $ips [$ip] = $time;    }   }  }  fclose ($ipfamily);  $ipfamily = fopen ($visitorips, "w");  foreach ($ips $key => $value) {   $line = "$key; $value\n";   $write = fputs ($ipfamily, $line);  }  $line = "$ipaddress; $currenttime\n\n";  $write = fputs ($ipfamily, $line);  fclose ($ipfamily);  $keyips = array_keys ($ips);  // current ip  foreach ($keyips $computerip) {   if (trim ($ipaddress) == trim ($computerip)) {    $flags = 1;    break;   }  }   $computerfamilyhome = fopen ($counter, "r");  $line = fgets ($computerfamilyhome);  $count = trim ($line);  createcounterimage ($count);  $computerfamilyhome = fopen ($counter, "w");  if (!$flags) {   $count = (int) $count + 1;  }   $write = fputs ($computerfamilyhome, $count);   // creates captcha image text  function counterimage ($count) {   // size of image   $image = imagecreate (100, 30);   $choosebackgroundcolor = rand (0, 4);   $fontcolor0 = imagecolorallocate ($image, 255, 255, 255);   $fontcolor1 = imagecolorallocate ($image, 255, 5, 8);   $fontcolor2 = imagecolorallocate ($image, 0, 0, 0);   $fontcolor3 = imagecolorallocate ($image, 127, 22, 199);   $fontcolor4 = imagecolorallocate ($image, 252, 149, 26);   $fontcolor5 = imagecolorallocate ($image, 88, 211, 0);   $fontcolor = array (fontcolor1, fontcolor2, fontcolor3, fontcolor4, fontcolor5);   $backgroundcolor = $fontcolor [$choosebackgroundcolor];   $newstring = $count;   imagefill ($image, 0, 0, $backgroundcolor);   imagestring ($image, 10, 14, 4, $newstring, $fontcolor0);   imagepng ($image, "counter.png");   header ("content-type: image/png");   imagepng ($image);   echo $image;   imagedestroy ($image);   } ?> 


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -