Jump to content

Recommended Posts

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");

 

?>

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
?> 

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

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?

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>

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.

<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>

<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...

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! :P

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
?>

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  :-)

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.