You're off to a good start. The first error I see is how you have the file opened. Opening with mode "a" will only allow you to write to the file. You will need to be able to read the file to know how many people visited before. You'll need to open it with r+, which will put the file pointer (where you are reading from) at the beginning of the file.
The next step, after opening the file, is to read the number already in it. We will use two functions to do this: fread() and filesize(). Fread() allows you to read parts of a file and filesize() returns the filesize, in bytes, of the specified file. Here's the code to read all the data in a file:
fread($fp,filesize($counter));
After we have read the amount of previous visitors, we'll need to come up with the new amount. Using the above line, we have just read, but not stored any data. You can set this equal to a variable by putting the variable name followed by an equal before it:
$num = fread($fp,filesize($counter));
Now, we increment $num. You can do this two ways: using the ++ operator, or by adding one:
$num++;
$num = $num + 1;
Obviously, you can't use both (it'll +2). Now, we need to restore the variable to the file. You can use fwrite() here. However, since we've read all of the data, the filepointer is now at the end of the file! We'll have to reset this using fseek():
fseek($fp,0,SEEK_SET);
Alright, now that we're back to the beginning of the file, we can assume it's safe to write. No number that is incremented is shorter in character value than its unincremented value, so we can write over it without any fear of overlap. For this, we are going to use fwrite(), as mentioned above. Fwrite() is probably the most strait-forward file command in PHP, all you need to tell it is what file pointer and what to write:
fwrite($fp,$num);
Alright! Close your file and echo out $num. You're done!