Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
Digital Lifestyle
Web Design and Hosting
Counter of sorts
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="muso" data-source="post: 2552" data-attributes="member: 40"><p>here you go: <a href="https://www.thoughtco.com/web-page-hit-counter-2693831" target="_blank">PHP hit counter</a></p><p></p><p>Just the basic outline so you can understand what the code means;</p><ul> <li data-xf-list-type="ul">Anything with a $ in front of it is a variable, it is either being assigned or being displayed</li> <li data-xf-list-type="ul">Page 2 is optional, leave it out if you want an invisible counter, just make sure you add the very first line of it to the page you want counted (the <?php include... ?> one) at the top of your document.</li> <li data-xf-list-type="ul">The stuff between the <? and ?> is the php code, and can be put inside another document or linked to as a separate one.</li> <li data-xf-list-type="ul">To use php scripts in a html document (not as a standalone one), the eaisest way is to rename your file from .html to .php</li> </ul><p></p><p>What the script does: The file countFunction.php is a file that is separate from everything else and linked to from your index.php page (make sure your page is index.php not index.html). When the browser loads the page it also loads and executes that file. The php code asks the browser if the user has been counted already (in the current session) and if not, writes to the file counter.txt the new number of visitors.</p><p></p><p>Something I find really useful but is completely unrelated: If you have a site where the same thing appears on each page but changes often (i.e. a news bar on the side or something you want to spotlight), put the corresponding code with all the html tags into a file, yourfilenamehere.txt. Take it out of the original page, and put this line of code into where you want the information displayed: <?php include "yourfilenamehere.txt"; ?>. Change index.html or whatever page it is to index.php and you're away. If you change the text file it will change the html file. So you can add this piece of code to any page you want and it will always display the same.</p><p></p><p>[edit]Oops, for the function to be called that does all the work, you will <strong>need</strong> to have the line <?php Counter(); ?> in there somewhere... but this will display the number of hits. Edit the last line "echo $finalcount" out of countFunction.php.</p></blockquote><p></p>
[QUOTE="muso, post: 2552, member: 40"] here you go: [URL='https://www.thoughtco.com/web-page-hit-counter-2693831']PHP hit counter[/URL] Just the basic outline so you can understand what the code means; [LIST] [*]Anything with a $ in front of it is a variable, it is either being assigned or being displayed [*]Page 2 is optional, leave it out if you want an invisible counter, just make sure you add the very first line of it to the page you want counted (the <?php include... ?> one) at the top of your document. [*]The stuff between the <? and ?> is the php code, and can be put inside another document or linked to as a separate one. [*]To use php scripts in a html document (not as a standalone one), the eaisest way is to rename your file from .html to .php [/LIST] What the script does: The file countFunction.php is a file that is separate from everything else and linked to from your index.php page (make sure your page is index.php not index.html). When the browser loads the page it also loads and executes that file. The php code asks the browser if the user has been counted already (in the current session) and if not, writes to the file counter.txt the new number of visitors. Something I find really useful but is completely unrelated: If you have a site where the same thing appears on each page but changes often (i.e. a news bar on the side or something you want to spotlight), put the corresponding code with all the html tags into a file, yourfilenamehere.txt. Take it out of the original page, and put this line of code into where you want the information displayed: <?php include "yourfilenamehere.txt"; ?>. Change index.html or whatever page it is to index.php and you're away. If you change the text file it will change the html file. So you can add this piece of code to any page you want and it will always display the same. [edit]Oops, for the function to be called that does all the work, you will [B]need[/B] to have the line <?php Counter(); ?> in there somewhere... but this will display the number of hits. Edit the last line "echo $finalcount" out of countFunction.php. [/QUOTE]
Verification
Name this item 🌈
Post reply
Forums
Digital Lifestyle
Web Design and Hosting
Counter of sorts
Top