php help

I am creating a hit counter and I am working on the File hits.txt first.

The code I have in this file is

<? php
$hits = file_get_contents {"hits.txt"}
$hits = $hits +1

?>

Can you tell me if I need any other code in here befor I go to make the PhP file?

Thank you
 
Thanks but

Ok I don't know if I know were to put the hits.txt code in with all the other code.

Do you mind just giving me the whole code that I have to put into my HITS.TXT File?
Thanks
 
Code:
$hits = file_get_contents {"hits.txt"}
$hits = $hits +1

The above code will throw out a syntax error. I would setup your hit counter in a separate PHP file, we'll name it hits.php here, in your public_html directory and include it in your index page like so;

Code:
  <html>
  <head>
<title>Page Title</title>
</head>
  <body>
<?php
if(file_exists("hits.php")){

         include("hits.php"); } else { echo"Hit counter is down"; }
?>
  </body>
  </html>

This is a very basic html template, you'll want to implement your own, of course.. but it should help you understand how to include the PHP hits counter within your site.

On a side note, you don't need to use an if/else statement, I only included it so that if the index can't find the hits.php file, you can at least see that the index is trying to load the script. The 'Hit Counter is down' phrase can only be seen if you don't put the hits.php file in the proper place on your server, or if the hits.php script malfunctions and the index cannot load it. If you'd prefer to not use an if/else statement, simply implement the following code instead;

Code:
  <html>
  <head>
<title>Page Title</title>
</head>
  <body>
<?php
     include("hits.php");
?>
  </body>
  </html>
 
thanks but

OK thank you for all your help but I think I am getting mixed up.

The code

$hits = file_get_contents {"hits.txt"}
$hits = $hits +1

I should past this into a Notepad file and save it as what hits.TXT

Just do this one step befor moving on thank you.
 
Thanks but

The code I am useing is

<? php
$hits = file_get_contents {"hits.txt"}
$hits = $hits +1

?>

As you can see I do have the hits.txt in it is this what you meen?????

And the whole code goes between the HTML Body Tags in my Index.html page right???
 
Back
Top