PDA

View Full Version : Are there any PHP experts around?



25-05-2002, 08:28 PM
The following code works well on my Windows 98, Apache, PHP. but when I upload it to the website does not work.

@ $fp=fopen('visit.txt','a',17);
@ $hit= Date('H:i:s d-n-y\n');
@ fwrite($fp,$hit);
@ fclose($fp);

If you think it looks like 'C' you are right, the @ at the beginning of the line tells PHP to carry on and not stop at any errors, so the rest of the PHP code will work. I tried it without '17', 'b' in place of 'a' and many other things but can not get it to work, while the rest of the PHP code works well. All it does is put the time and date (e.g. 18:54:54 25-5-02) to a text file each time someone visits the web site. Otherwise I will have to wait until Monday to ring the website host to help solve the problem.

25-05-2002, 11:04 PM
Eric,

I'm not a PHP expert yet, but I'm learning very slowly. The first thing I thought of when I read your post was that your web server may not allow writing to files on the site, which could be why it doesn't work. I know the server my site is hosted on doesn't allow writing to the site except through the ftp server, unless I specifically request it.

Looking through my PHP manual, I'm wondering why you've got the '17' in there, shouldn't it rather be in the 'fwrite'?; also try putting a '/' in front of the file name eg '/visit.txt' rather than 'visit.txt'.

The 'b' won't work unless your webserver is Windows based, which a regular apache webserver will not be.

Excuse my ignorance if I've got everything wrong :)

HTH

Mike.

26-05-2002, 12:32 AM
Eric,

Had another think about it, and a little play around, and I'd suggest that its probably fairly likely that the webserver permissions need to be changed to allow for writing to it.

Mike.

26-05-2002, 12:43 AM
Thank you Mike
For your comments I gave your suggestion ('/visit.txt') a try and it still did not work, maybe you are right that I can write files from PHP.

'17' is a optional extra and should be in fwrite as you said Mike when things did not work I added it in the wrong place, silly me I thought it was strange when I made it 10 and it still wrote 16 charactors to file, (that is the number of characters you write to file plus one for 'End Of File'),