Help for simple PHP script |
Help for simple PHP script |
denmarks |
Aug 26 2018, 03:50 PM
Post
#1
|
Advanced Member Group: Members Posts: 207 Joined: 17-January 08 Member No.: 4,734 |
I know hardly anything about PHP and am trying to create a very simple script. It is the beginning of a web counter.
There is a file named count.log that has a single line in it with a zero (0). I want to read the file and create a gif displaying the number. One is then added to the count and it is written back to the log file. The gif displays but I do not believe the the log is read or written. The value of 0 appears which is what I initialize the log file to. CODE <?php $count_file = 'count.log'; $my_img = imagecreatefromgif ("count.gif"); $textcolor = imagecolorallocate($my_img, 0, 0, 0); $count = 0; file_get_contents($count_file, $count); imagestring($my_img, 4, 2, 3, "Counter $count", $textcolor); $count = $count + 1; file_put_contents($count_file, $count); header( "Content-type: image/png" ); imagepng( $my_img ); imagedestroy( $my_img ); ?> |
denmarks |
Aug 27 2018, 06:25 PM
Post
#2
|
Advanced Member Group: Members Posts: 207 Joined: 17-January 08 Member No.: 4,734 |
Thanks for your help. Since this was just an experiment I think I will go no further.
|
CharlesEF |
Aug 27 2018, 08:12 PM
Post
#3
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
|
denmarks |
Aug 28 2018, 08:58 AM
Post
#4
|
Advanced Member Group: Members Posts: 207 Joined: 17-January 08 Member No.: 4,734 |
Thanks for your help. Since this was just an experiment I think I will go no further. Those 2 lines shouldn't affect anything except showing errors. You did put them after '<?php' and before any of your PHP code right? I get: The image "http://www.dmmarks.com/count.php" cannot be displayed because it contains errors. CODE <?php ini_set('display_errors', 'On'); error_reporting(E_ALL); $count_file = "count.data"; $my_img = imagecreatefromgif ("count.gif"); $textcolor = imagecolorallocate($my_img, 0, 0, 0); $count = file_get_contents($count_file); imagestring($my_img, 4, 2, 3, "Counter $count", $textcolor); $count += 1; file_put_contents($count_file, $count); header( "Content-type: image/png" ); imagepng( $my_img ); imagedestroy( $my_img ); ?> |
Lo-Fi Version | Time is now: 27th April 2024 - 01:22 AM |