Posts: 0
Threads: 0
Joined: Jun 2021
Reputation:
0
Level: inf []
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
Wassup guys, here is some php code I made for my website to count the amount of unique page views.I tried my best to explain each line of code with a comment above.
Create a new file "count.php" and add the following code:
PHP Code: <?php
/* get the IP address of the user */ $getra = $_SERVER['REMOTE_ADDR'];
/* Encrypt the IP address with sha1 in brackets; also get it ready for the next line with \n */ $printip = "<" . sha1($getra) . ">\n";
/* get the file name where we are printing our encrypted IPs */ $getfile = "ipfile.txt";
/* Open that file with read/write access; If it doesn't exist it will create it. */ $ipfile = fopen($getfile, "a+") or die("Unable to open file!");
/* count the amount of lines in the ipfile.txt(AKA: counting how many IP's are on the list) */ $countipfile = count(file($getfile));
/* read the file we opened */ $ipget = fread($ipfile, filesize($getfile));
/* if it contains the ip address already, do nothing. If it doesn't have the IP address on file, write it & +1. */ if(strpos($ipget, $printip) !== false){ }else{ fwrite($ipfile, $printip);
/* since the new visitor wont see his view on the counter until he refreshes his browser; */ $countipfile++; /* We account for his IP that wasn't initially counted in the list by adding 1 (because it wasn't there) */ /* Once he refreshes, his IP is already on the list and counted. */ }
/* write the amount of unique visits. */ $theCount = "Unique Website Views: ". $countipfile . ""; ?>
Now, whatever page you want to record the amount of visitors on, add the following code (preferably to the head):
(So if someone views a page with this code in it, their IP will be logged)
PHP Code: <?php include count.php; ?>
Now to print your unique page counter, use the following code (make sure the line of code above is included somewhere in the page):
I hope you guys enjoy this, if you have any questions comment below and I will try to help you
|
Posts: 0
Threads: 0
Joined: Mar 2020
Reputation:
0
Level: inf []
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
A simple, yet very effective piece of code.
Excellent use of variables and conditional statements.
A job well done.
|
Posts: 0
Threads: 0
Joined: Sep 2021
Reputation:
0
Level: inf []
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
I was trying to do this as well, but looks like no more need to code.
Thank you, I will modify and integrate into my website.
|
Posts: 0
Threads: 0
Joined: Jul 2018
Reputation:
0
Level: inf []
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
Quote:(07-26-2020, 07:22 AM)mothered Wrote: [To see links please register here] A simple, yet very effective piece of code.
Excellent use of variables and conditional statements.
A job well done.
Thank you :smile: Figured I release the code as I made it in 10-20 minutes and it could really help others.
Quote:(07-26-2020, 10:03 AM)Mr.Kurd Wrote: [To see links please register here] I was trying to do this as well, but looks like no more need to code.
Thank you, I will modify and integrate into my website.
No problem bud :smile: I'm glad you found this useful
|
Posts: 0
Threads: 0
Joined: Aug 2018
Reputation:
0
Level: inf []
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
Quote:(07-26-2020, 07:30 PM)Crimin4L Wrote: [To see links please register here]
Quote: (07-26-2020, 07:22 AM)mothered Wrote: [To see links please register here] A simple, yet very effective piece of code.
Excellent use of variables and conditional statements.
A job well done.
Thank you :smile: Figured I release the code as I made it in 10-20 minutes and it could really help others.
Quote:(07-26-2020, 10:03 AM)Mr.Kurd Wrote: [To see links please register here] I was trying to do this as well, but looks like no more need to code.
Thank you, I will modify and integrate into my website.
No problem bud :smile: I'm glad you found this useful :smile:
Although i don't use php i was able to read this lol
|
Posts: 0
Threads: 0
Joined: Mar 2018
Reputation:
0
Level: inf []
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
Quote:(07-26-2020, 07:40 PM)kRyPt0n Wrote: [To see links please register here]
Quote: (07-26-2020, 07:30 PM)Crimin4L Wrote: [To see links please register here]
Quote: (07-26-2020, 07:22 AM)mothered Wrote: [To see links please register here] A simple, yet very effective piece of code.
Excellent use of variables and conditional statements.
A job well done.
Thank you :smile: Figured I release the code as I made it in 10-20 minutes and it could really help others.
Quote:(07-26-2020, 10:03 AM)Mr.Kurd Wrote: [To see links please register here] I was trying to do this as well, but looks like no more need to code.
Thank you, I will modify and integrate into my website.
No problem bud :smile: I'm glad you found this useful :smile:
Although i don't use php i was able to read this lol
PHP is easy to use and you can understand and learn so fast.... I nver had a cource or taken any course for learning PHP..
|
Posts: 0
Threads: 0
Joined: Oct 2020
Reputation:
0
Level: inf []
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
Quote:(07-26-2020, 07:30 PM)Crimin4L Wrote: [To see links please register here] Figured I release the code as I made it in 10-20 minutes and it could really help others.
It certainly Is very useful.
I have a security site (not a blog) that I can add your code.
Much appreciated.
|
Posts: 0
Threads: 0
Joined: May 2023
Reputation:
0
Level: inf []
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
Quote:(07-27-2020, 03:48 AM)mothered Wrote: [To see links please register here]
Quote: (07-26-2020, 07:30 PM)Crimin4L Wrote: [To see links please register here] Figured I release the code as I made it in 10-20 minutes and it could really help others.
It certainly Is very useful.
I have a security site (not a blog) that I can add your code.
Much appreciated.
You're very welcome my friend, anything I can do to help
|
Posts: 0
Threads: 0
Joined: Oct 2022
Reputation:
0
Level: inf []
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
Quote:(07-26-2020, 06:56 AM)Crimin4L Wrote: [To see links please register here] Wassup guys, here is some php code I made for my website to count the amount of unique page views.I tried my best to explain each line of code with a comment above.
Create a new file "count.php" and add the following code:
PHP Code: <?php
/* get the IP address of the user */ $getra = $_SERVER['REMOTE_ADDR'];
/* Encrypt the IP address with sha1 in brackets; also get it ready for the next line with \n */ $printip = "<" . sha1($getra) . ">\n";
/* get the file name where we are printing our encrypted IPs */ $getfile = "ipfile.txt";
/* Open that file with read/write access; If it doesn't exist it will create it. */ $ipfile = fopen($getfile, "a+") or die("Unable to open file!");
/* count the amount of lines in the ipfile.txt(AKA: counting how many IP's are on the list) */ $countipfile = count(file($getfile));
/* read the file we opened */ $ipget = fread($ipfile, filesize($getfile));
/* if it contains the ip address already, do nothing. If it doesn't have the IP address on file, write it & +1. */ if(strpos($ipget, $printip) !== false){ }else{ fwrite($ipfile, $printip);
/* since the new visitor wont see his view on the counter until he refreshes his browser; */ $countipfile++; /* We account for his IP that wasn't initially counted in the list by adding 1 (because it wasn't there) */ /* Once he refreshes, his IP is already on the list and counted. */ }
/* write the amount of unique visits. */ $theCount = "Unique Website Views: ". $countipfile . ""; ?>
Now, whatever page you want to record the amount of visitors on, add the following code (preferably to the head):
(So if someone views a page with this code in it, their IP will be logged)
PHP Code: <?php include count.php; ?>
Now to print your unique page counter, use the following code (make sure the line of code above is included somewhere in the page):
I hope you guys enjoy this, if you have any questions comment below and I will try to help you :smile:i dont know what this does but this looks like it works
|
Posts: 0
Threads: 0
Joined: Sep 2016
Reputation:
0
Level: inf []
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
Quote:(07-27-2020, 09:00 AM)bigStackz Wrote: [To see links please register here]
Quote: (07-26-2020, 06:56 AM)Crimin4L Wrote: [To see links please register here] Wassup guys, here is some php code I made for my website to count the amount of unique page views.I tried my best to explain each line of code with a comment above.
Create a new file "count.php" and add the following code:
PHP Code: <?php
/* get the IP address of the user */ $getra = $_SERVER['REMOTE_ADDR'];
/* Encrypt the IP address with sha1 in brackets; also get it ready for the next line with \n */ $printip = "<" . sha1($getra) . ">\n";
/* get the file name where we are printing our encrypted IPs */ $getfile = "ipfile.txt";
/* Open that file with read/write access; If it doesn't exist it will create it. */ $ipfile = fopen($getfile, "a+") or die("Unable to open file!");
/* count the amount of lines in the ipfile.txt(AKA: counting how many IP's are on the list) */ $countipfile = count(file($getfile));
/* read the file we opened */ $ipget = fread($ipfile, filesize($getfile));
/* if it contains the ip address already, do nothing. If it doesn't have the IP address on file, write it & +1. */ if(strpos($ipget, $printip) !== false){ }else{ fwrite($ipfile, $printip);
/* since the new visitor wont see his view on the counter until he refreshes his browser; */ $countipfile++; /* We account for his IP that wasn't initially counted in the list by adding 1 (because it wasn't there) */ /* Once he refreshes, his IP is already on the list and counted. */ }
/* write the amount of unique visits. */ $theCount = "Unique Website Views: ". $countipfile . ""; ?>
Now, whatever page you want to record the amount of visitors on, add the following code (preferably to the head):
(So if someone views a page with this code in it, their IP will be logged)
PHP Code: <?php include count.php; ?>
Now to print your unique page counter, use the following code (make sure the line of code above is included somewhere in the page):
I hope you guys enjoy this, if you have any questions comment below and I will try to help you :smile:i dont know what this does but this looks like it worksThe OP has placed comments (denoted by /* and */) explaining what Its respective code does.
|
|