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: 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 );
?>
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 31 2018, 03:51 AM
Post #2


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



Also, the Content-Type header should be image/gif if you create a GIF image (though browsers may display it anyway).
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
denmarks
post Aug 31 2018, 08:46 AM
Post #3


Advanced Member
****

Group: Members
Posts: 207
Joined: 17-January 08
Member No.: 4,734



QUOTE(Christian J @ Aug 31 2018, 01:51 AM) *

Also, the Content-Type header should be image/gif if you create a GIF image (though browsers may display it anyway).


Thanks for your help but it still doesn't increment. It is probably my host. I will check with them some day. I have also posted the question at the 1and1 forum and am still waiting for a response.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Aug 31 2018, 12:25 PM
Post #4


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



QUOTE(denmarks @ Aug 31 2018, 08:46 AM) *

Thanks for your help but it still doesn't increment. It is probably my host. I will check with them some day. I have also posted the question at the 1and1 forum and am still waiting for a response.

It increments and displays the .png with no error. Also, when I inserted my 2 lines for error checking I got actual error messages, don't remember them now.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
denmarks
post Aug 31 2018, 12:31 PM
Post #5


Advanced Member
****

Group: Members
Posts: 207
Joined: 17-January 08
Member No.: 4,734



QUOTE(CharlesEF @ Aug 31 2018, 10:25 AM) *

QUOTE(denmarks @ Aug 31 2018, 08:46 AM) *

Thanks for your help but it still doesn't increment. It is probably my host. I will check with them some day. I have also posted the question at the 1and1 forum and am still waiting for a response.

It increments and displays the .png with no error. Also, when I inserted my 2 lines for error checking I got actual error messages, don't remember them now.


I must be missing something on the server. I get errors with

ini_set('display_errors', 'On');
error_reporting(E_ALL);

but if I leave out ini_set... there is no error.

I read about a php.ini file. Do I need that? Also I can not find a php log file to look for errors.
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: 28th March 2024 - 03:31 AM