Ricnewbie Posted January 27, 2008 Share Posted January 27, 2008 Hi all, Could someone please tell me why this script refuses to work - I have been looking at it for hours and have no idea what is wrong. I have PHP4 installed on my hosts server and my index page is correctly called index.php All I want the script to do is act as a basic visitor counter - writing the number of visitors to a txt file and then emailing me with the result. Every time I insert this script into my index.php page I get an error saying "fcommand.fopen" or somethig similiar to those words. Please help - thanks in advance. <?php //open the file handler $fp=fopen("counterdata.txt","r"); //Read the previous count $count=fgets($fp,1024); //close the file. fclose($fp); $fw=fopen("counterdata.txt","w"); //Increment the counter $cnew=$count+1; //write the counter back to the log file - counterdata.txt $countnew=fputs($fw,$count+1); fclose($fw) $address = "info@mywebsite.co.uk"; mail($address, "Visitor at www.mywebsite.co.uk", "Total number of visits is now : $cnew"); ?> Link to comment https://forums.phpfreaks.com/topic/88010-solved-this-mini-script-is-driving-me-nuts/ Share on other sites More sharing options...
AndyB Posted January 27, 2008 Share Posted January 27, 2008 ... or somethig similiar to those words. The exact words would be much more help in solving this one. Also, is your text file write-enabled, i.e. permissions set properly? Link to comment https://forums.phpfreaks.com/topic/88010-solved-this-mini-script-is-driving-me-nuts/#findComment-450315 Share on other sites More sharing options...
Ricnewbie Posted January 27, 2008 Author Share Posted January 27, 2008 fcommand.fopen appears on my index page and the .txt file is set to 755 permissions. Link to comment https://forums.phpfreaks.com/topic/88010-solved-this-mini-script-is-driving-me-nuts/#findComment-450522 Share on other sites More sharing options...
phpSensei Posted January 27, 2008 Share Posted January 27, 2008 make a .txt file called counter, and add a 0 in it. <?php ###################################################### // This script will add a counter on your website // First thing is first, we need to define where the // data is $file = fopen("counter.txt","r+"); // Open the file R+ (read and write) $get_data = fread($file,512); // Read the counter.txt $new_data = $get_data + 1; // Adds 1 to the counter echo $new_data; // Echo the Counter fseek($file, 0) ; //Go back to line 1 in our counter file fwrite($file, $new_data) ; // Save the new data fclose($file) ; //closes the file ?> Link to comment https://forums.phpfreaks.com/topic/88010-solved-this-mini-script-is-driving-me-nuts/#findComment-450523 Share on other sites More sharing options...
Ricnewbie Posted January 27, 2008 Author Share Posted January 27, 2008 I will try what you just typed a bit later - thank you very much. CVould you please tell me how is that different from what I had - it seems to be doing the same thing ??? Link to comment https://forums.phpfreaks.com/topic/88010-solved-this-mini-script-is-driving-me-nuts/#findComment-450531 Share on other sites More sharing options...
phpSensei Posted January 27, 2008 Share Posted January 27, 2008 I will try what you just typed a bit later - thank you very much. CVould you please tell me how is that different from what I had - it seems to be doing the same thing ??? Well lets see, I didnt use fput, fgets, $file = fopen("counter.txt","r+"); $get_data = fread($file,512); fseek($file, 0) ; //Go back to line 1 in our counter file fwrite($file, $new_data) ; // Save the new data fclose($file) ; //closes the file Link to comment https://forums.phpfreaks.com/topic/88010-solved-this-mini-script-is-driving-me-nuts/#findComment-450536 Share on other sites More sharing options...
phpSensei Posted January 27, 2008 Share Posted January 27, 2008 Differently Written? yes Does the Same stuff?, yes Link to comment https://forums.phpfreaks.com/topic/88010-solved-this-mini-script-is-driving-me-nuts/#findComment-450537 Share on other sites More sharing options...
Ricnewbie Posted January 27, 2008 Author Share Posted January 27, 2008 Unfortunately that didnt work either - now I get the following error message displayed on my indey page : Parse error: syntax error, unexpected T_VARIABLE in /home/fhlinux176/p/mywebsite.co.uk/user/htdocs/index.php on line 21 Link to comment https://forums.phpfreaks.com/topic/88010-solved-this-mini-script-is-driving-me-nuts/#findComment-450539 Share on other sites More sharing options...
phpSensei Posted January 27, 2008 Share Posted January 27, 2008 Unfortunately that didnt work either - now I get the following error message displayed on my indey page : Parse error: syntax error, unexpected T_VARIABLE in /home/fhlinux176/p/mywebsite.co.uk/user/htdocs/index.php on line 21 Whats you're line 21? Link to comment https://forums.phpfreaks.com/topic/88010-solved-this-mini-script-is-driving-me-nuts/#findComment-450541 Share on other sites More sharing options...
Ricnewbie Posted January 27, 2008 Author Share Posted January 27, 2008 Here is the complete page source code of my index.php page - just in case that helps. <html> <head> <title>my site</title> <meta http-equiv="imagetoolbar" content="no" /><meta name="author" content="Richard Summers" /> <meta name="copyright" content="Richard Summers" /> <meta name="date" content="01-01-2008" /> <meta name="content-language" content="en-us" /> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <link rel="icon" href="favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <center> <img src="title.jpg" alt="Title" border="0" /> <br> <img src="videobox.jpg" /img> <br> <img src="techniques.jpg" /img> Link to comment https://forums.phpfreaks.com/topic/88010-solved-this-mini-script-is-driving-me-nuts/#findComment-450545 Share on other sites More sharing options...
Ricnewbie Posted January 27, 2008 Author Share Posted January 27, 2008 Line 21 was where the <?php code started. Link to comment https://forums.phpfreaks.com/topic/88010-solved-this-mini-script-is-driving-me-nuts/#findComment-450546 Share on other sites More sharing options...
Ricnewbie Posted January 27, 2008 Author Share Posted January 27, 2008 My post has left out the last 3 lines which are </center> </body> </html> Link to comment https://forums.phpfreaks.com/topic/88010-solved-this-mini-script-is-driving-me-nuts/#findComment-450556 Share on other sites More sharing options...
phpSensei Posted January 27, 2008 Share Posted January 27, 2008 My post has left out the last 3 lines which are </center> </body> </html> Can you insert the entire script with the script i gave you in a CODE tag please? Just need to examine it well. If you have any includes, sessions starts, on top of the pages, include those too. Include all scripts. one sec, ill post a working copy. Link to comment https://forums.phpfreaks.com/topic/88010-solved-this-mini-script-is-driving-me-nuts/#findComment-450558 Share on other sites More sharing options...
phpSensei Posted January 27, 2008 Share Posted January 27, 2008 http://render-works.com/VideoGraber/count.php Link to comment https://forums.phpfreaks.com/topic/88010-solved-this-mini-script-is-driving-me-nuts/#findComment-450559 Share on other sites More sharing options...
Ricnewbie Posted January 27, 2008 Author Share Posted January 27, 2008 <html> <head> <title>my site</title> <meta http-equiv="imagetoolbar" content="no" /><meta name="author" content="Richard Summers" /> <meta name="copyright" content="Richard Summers" /> <meta name="date" content="01-01-2008" /> <meta name="content-language" content="en-us" /> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <link rel="icon" href="favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <?php ###################################################### // This script will add a counter on your website // First thing is first, we need to define where the // data is $file = fopen("counter.txt","r+"); // Open the file R+ (read and write) $get_data = fread($file,512); // Read the counter.txt $new_data = $get_data + 1; // Adds 1 to the counter echo $new_data; // Echo the Counter fseek($file, 0) ; //Go back to line 1 in our counter file fwrite($file, $new_data) ; // Save the new data fclose($file) ; //closes the file ?> <center> <img src="title.jpg" alt="Title" border="0" /> <br> <img src="videobox.jpg" /img> <br> <img src="techniques.jpg" /img> <br> <img src="benefits.jpg" /img> <br> <img src="store.jpg" /img> <br> <img src="contact.jpg" border="0" usemap="#Map" /img> <map name="Map" id="Map"> <area shape="rect" coords="28,52,568,138" href="mailto:info@mysite.co.uk" alt="E-mail Richard" /> </map> </center> </body> </html> Link to comment https://forums.phpfreaks.com/topic/88010-solved-this-mini-script-is-driving-me-nuts/#findComment-450564 Share on other sites More sharing options...
phpSensei Posted January 27, 2008 Share Posted January 27, 2008 <html> <head> <title>my site</title> <meta http-equiv="imagetoolbar" content="no" /><meta name="author" content="Richard Summers" /> <meta name="copyright" content="Richard Summers" /> <meta name="date" content="01-01-2008" /> <meta name="content-language" content="en-us" /> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <link rel="icon" href="favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <?php ###################################################### // This script will add a counter on your website // First thing is first, we need to define where the // data is $file = fopen("counter.txt","r+"); // Open the file R+ (read and write) $get_data = fread($file,512); // Read the counter.txt $new_data = $get_data + 1; // Adds 1 to the counter echo $new_data; // Echo the Counter fseek($file, 0) ; //Go back to line 1 in our counter file fwrite($file, $new_data) ; // Save the new data fclose($file) ; //closes the file ?> <center> <img src="title.jpg" alt="Title" border="0" /> <br> <img src="videobox.jpg" /img> <br> <img src="techniques.jpg" /img> <br> <img src="benefits.jpg" /img> <br> <img src="store.jpg" /img> <br> <img src="contact.jpg" border="0" usemap="#Map" /img> <map name="Map" id="Map"> <area shape="rect" coords="28,52,568,138" href="mailto:info@mysite.co.uk" alt="E-mail Richard" /> </map> </center> </body> </html> I posted that script on http://render-works.com/VideoGraber/count.php and it works fine. You need to chmod the file to 777, its just what i did... Link to comment https://forums.phpfreaks.com/topic/88010-solved-this-mini-script-is-driving-me-nuts/#findComment-450565 Share on other sites More sharing options...
Ricnewbie Posted January 27, 2008 Author Share Posted January 27, 2008 Currently the chmod is set to 755 - would that be the cause of the problem - displaying error messages on my index page ?? I will now try changing the permissions - THANK YOU Link to comment https://forums.phpfreaks.com/topic/88010-solved-this-mini-script-is-driving-me-nuts/#findComment-450581 Share on other sites More sharing options...
phpSensei Posted January 27, 2008 Share Posted January 27, 2008 Currently the chmod is set to 755 - would that be the cause of the problem - displaying error messages on my index page ?? I will now try changing the permissions - THANK YOU The problem is also your script, set the permission and use the script i provided. NP! Link to comment https://forums.phpfreaks.com/topic/88010-solved-this-mini-script-is-driving-me-nuts/#findComment-450585 Share on other sites More sharing options...
Ricnewbie Posted January 27, 2008 Author Share Posted January 27, 2008 I give up - Im still getting the same error message about line 21. Now im pissed ! Thanks for trying to help me - I really appreciate it. Link to comment https://forums.phpfreaks.com/topic/88010-solved-this-mini-script-is-driving-me-nuts/#findComment-450586 Share on other sites More sharing options...
phpSensei Posted January 27, 2008 Share Posted January 27, 2008 I give up - Im still getting the same error message about line 21. Now im pissed ! Thanks for trying to help me - I really appreciate it. Can you try this without the Html, just use a blank new page. Link to comment https://forums.phpfreaks.com/topic/88010-solved-this-mini-script-is-driving-me-nuts/#findComment-450589 Share on other sites More sharing options...
Ricnewbie Posted January 27, 2008 Author Share Posted January 27, 2008 I cant see the script you gave me - when i open the file i just get the html code without the php part. MY HEAD HURTS :-( Link to comment https://forums.phpfreaks.com/topic/88010-solved-this-mini-script-is-driving-me-nuts/#findComment-450592 Share on other sites More sharing options...
phpSensei Posted January 27, 2008 Share Posted January 27, 2008 I cant see the script you gave me - when i open the file i just get the html code without the php part. MY HEAD HURTS :-( I posted it for you <?php ###################################################### // This script will add a counter on your website // First thing is first, we need to define where the // data is $file = fopen("counter.txt","r+"); // Open the file R+ (read and write) $get_data = fread($file,512); // Read the counter.txt $new_data = $get_data + 1; // Adds 1 to the counter echo $new_data; // Echo the Counter fseek($file, 0) ; //Go back to line 1 in our counter file fwrite($file, $new_data) ; // Save the new data fclose($file) ; //closes the file ?> Link to comment https://forums.phpfreaks.com/topic/88010-solved-this-mini-script-is-driving-me-nuts/#findComment-450593 Share on other sites More sharing options...
Ricnewbie Posted January 27, 2008 Author Share Posted January 27, 2008 Could you email the file that I can upload (I already have the counter.txt file 777). I can then upload the file you give me and see if it works. Link to comment https://forums.phpfreaks.com/topic/88010-solved-this-mini-script-is-driving-me-nuts/#findComment-450597 Share on other sites More sharing options...
phpSensei Posted January 27, 2008 Share Posted January 27, 2008 Could you email the file that I can upload (I already have the counter.txt file 777). I can then upload the file you give me and see if it works. You were suposed to chmod the counter script file to 777 hehe, not the counter.txt Link to comment https://forums.phpfreaks.com/topic/88010-solved-this-mini-script-is-driving-me-nuts/#findComment-450600 Share on other sites More sharing options...
Ricnewbie Posted January 27, 2008 Author Share Posted January 27, 2008 Ok - problem solved - I downloaded another counter script that had the code (that writes the number of visitors) in a separate file and I then just wrote an include line in my main index page. All working perfect now. Thank you so much for your patience and assistance. This PHP stuff is bloody hard for a newbie to get to terms with :-) Link to comment https://forums.phpfreaks.com/topic/88010-solved-this-mini-script-is-driving-me-nuts/#findComment-450646 Share on other sites More sharing options...
Recommended Posts