The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> Help for simple PHP script
denmarks
post Aug 26 2018, 03:50 PM
Post #1


Advanced Member
****

Group: Members
Posts: 200
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 );
?>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
Christian J
post Aug 27 2018, 05:55 PM
Post #2


.
********

Group: WDG Moderators
Posts: 8,245
Joined: 10-August 06
Member No.: 7



I tested it in XAMPP, and it seemed to work as expected.

I assume you're testing on an online server? Maybe the web host support can tell if the server is using an unusual configuration.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Aug 28 2018, 09:07 AM
Post #3


.
********

Group: WDG Moderators
Posts: 8,245
Joined: 10-August 06
Member No.: 7



QUOTE(Christian J @ Aug 28 2018, 12:55 AM) *

I tested it in XAMPP, and it seemed to work as expected.

I should clarify that I only tested writing to the count.data file. The image creation part didn't work for me (I got a broken image).
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic
denmarks   Help for simple PHP script   Aug 26 2018, 03:50 PM
CharlesEF   You need to assign the results of the file read to...   Aug 27 2018, 01:30 AM
denmarks   You need to assign the results of the file read t...   Aug 27 2018, 09:51 AM
CharlesEF   After the file read the variable $count will ...   Aug 27 2018, 01:18 PM
denmarks   After the file read the variable $count will...   Aug 27 2018, 01:30 PM
Christian J   Have you made the log file writable with CHMOD (us...   Aug 27 2018, 01:37 PM
denmarks   Have you made the log file writable with CHMOD (u...   Aug 27 2018, 02:17 PM
Christian J   I looked at the file permissions and it is read, ...   Aug 27 2018, 03:52 PM
denmarks   I looked at the file permissions and it is read,...   Aug 27 2018, 04:07 PM
CharlesEF   We can't see PHP code from a web page. But, i...   Aug 27 2018, 02:25 PM
denmarks   We can't see PHP code from a web page. But, ...   Aug 27 2018, 02:50 PM
Christian J   I tested it in XAMPP, and it seemed to work as exp...   Aug 27 2018, 05:55 PM
Christian J   I tested it in XAMPP, and it seemed to work as ex...   Aug 28 2018, 09:07 AM
denmarks   Thanks for your help. Since this was just an exper...   Aug 27 2018, 06:25 PM
CharlesEF   Thanks for your help. Since this was just an expe...   Aug 27 2018, 08:12 PM
denmarks   [quote name='denmarks' post='136098' date='Aug 27...   Aug 28 2018, 08:58 AM
CharlesEF   This script works for me, with a test .gif I had. ...   Aug 31 2018, 02:55 AM
Christian J   Also, the Content-Type header should be image/gif ...   Aug 31 2018, 03:51 AM
denmarks   Also, the Content-Type header should be image/gif...   Aug 31 2018, 08:46 AM
CharlesEF   Thanks for your help but it still doesn't inc...   Aug 31 2018, 12:25 PM
denmarks   Thanks for your help but it still doesn't in...   Aug 31 2018, 12:31 PM
CharlesEF   I must be missing something on the server. I get ...   Aug 31 2018, 03:11 PM
denmarks   I must be missing something on the server. I get...   Aug 31 2018, 03:23 PM
CharlesEF   I guess you should ask your hosting company where ...   Aug 31 2018, 07:59 PM


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 11th November 2019 - 02:45 PM