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
2 Pages V < 1 2  
Reply to this topicStart new topic
Replies(20 - 23)
denmarks
post Aug 31 2018, 12:31 PM
Post #21


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
CharlesEF
post Aug 31 2018, 03:11 PM
Post #22


Programming Fanatic
********

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



QUOTE(denmarks @ Aug 31 2018, 12:31 PM) *

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.

The php.ini file should be in the same directory that PHP was installed in, I have never heard of anyone needing to create the file themselves. The 'php-errors.log' file should be in your temp directory, the php.ini file points to the directory.

Are you running the script from a local web server OR from your online web server?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
denmarks
post Aug 31 2018, 03:23 PM
Post #23


Advanced Member
****

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



QUOTE(CharlesEF @ Aug 31 2018, 01:11 PM) *

QUOTE(denmarks @ Aug 31 2018, 12:31 PM) *

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.

The php.ini file should be in the same directory that PHP was installed in, I have never heard of anyone needing to create the file themselves. The 'php-errors.log' file should be in your temp directory, the php.ini file points to the directory.

Are you running the script from a local web server OR from your online web server?


I have my own webspace. I do not install PHP. I do not have a temp directory. It is being run from an online web server (1and1)
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Aug 31 2018, 07:59 PM
Post #24


Programming Fanatic
********

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



I guess you should ask your hosting company where the INI and ERROR files are located. I can login to my account and have access to that information.

If you really want to learn PHP you should install a web server on your local computer. That way you KNOW when a script works correctly and can talk to your hosting company about it. I know nothing about 1and1.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

2 Pages V < 1 2
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: 14th May 2024 - 11:13 AM