Pages: [1]   Go Down
Send this topic | Print
Author Topic: [Script] Online Site Visitors (XDD Required)  (Read 2037 times)
d3xt3r
Guest
« on: June 24, 2008, 12:24:48 PM »

This script requires XDD 2.5 be installed on your server. XDD is a simple to install FlatFile database system, that can be obtained here.

This script will allow you to display the current count of your sites online visitors using PHP and XDD FlatFile databasing. Since XDD has a tested file locking system beyond most, this script can function on sites with high traffic. You can set key functions at the top of the script.

Settings..

1. Data file can be any text file in any location on the web server.
2. Session time will determine how long to show a visitor as online since last active. (In Minutes)
3. The data file will be created automatically after first pageload. No need to create it.

Installing..

1. Copy ScriptA below and paste into all .PHP pages you wish to monitor current visitors. Or paste into a commonly included file on your web system.

2. Copy ScriptB and place anywhere you wish to display the current visitor count. But keep in mind, that ScriptB must be placed on a page that runs ScriptA and ScriptA must be run before ScriptB.

ScriptA
Code:
<?php
###################################
# Xegment Delta | Online Visitors #
#                                 #
#    Script Requires XDD 2.5      #
#                                 #
#   http://d3xt3r.net/xdd.php     #
#                                 #
#           By D3xt3r             #
#                                 #
###################################
require_once("xdd.class.php");
$online_visitor_log="onlinevisitors.db";
$session_time=30;                                                                                         # Set Session Time (Minutes)
$ip=isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; # Get Users IP Address
$session_time=$session_time*60;                                                                           # Multiply Session Time By 60
$time_ahead=time()+$session_time;                                                                         # Set Session Time Ahead
if(!file_exists($online_visitor_log))                                                                     # If Data File Doesn't Exist
file_put_contents($online_visitor_log, " ");                                                              # Make Data File
xdd_replace($online_visitor_log,$ip,"|".$time_ahead,ID_OVERRIDE);                                         # Delete Past Occurances Of IP, And Add New
$detail_users=xdd_read($online_visitor_log,"|",ID_OVERRIDE,RV_OVERRIDE,R_ARRAY);                          # Get All Database Visits
foreach($detail_users as $detail_user){                                                                   # For Each Database Entry
$user_data=explode("|",$detail_user);                                                                     # Split Time And IP Address
if($user_data[1] < time())                                                                                # If Entry Time Less Than Current Time
xdd_delete($online_visitor_log,$detail_user,ID_OVERRIDE);                                                 # Delete Current Entry
}                                                                                                         # End "ForEach" Process
$online_visitors=count(xdd_read($online_visitor_log,"|",ID_OVERRIDE,R_ARRAY));                            # Count Visitors Online
echo $online_visitors;                                                                                    # Display Visitors Online
###################################
?>


ScriptB
Code:
<?php
#################
# Online Visitors
echo $online_visitors;
#################
?>

Logged
stang45
Extremely Random Person
Authority Member
****
Offline Offline

Posts: 719

The World is Random What About You?


WWW
« Reply #1 on: June 24, 2008, 12:33:10 PM »

D3xt3r did you come up with XDD?


Edit** You are awesome.
« Last Edit: June 25, 2008, 12:48:32 PM by stang45 » Logged

PHP Programmer for Life!!:!

Is oil really that important? Lets ask Bush!
Do you really need to spy on American Citizens? Lets ask Bush!
Is torture really necessary? Lets ask Bush!



Owner of Randomstand.com
d3xt3r
Guest
« Reply #2 on: June 24, 2008, 01:09:25 PM »

D3xt3r did you come up with XDD?

Yeah, when I got into PHP I was trying to find ways of storing data into text files. Cause I had loads of single files all around.. I came up with XDD, and it grew and grew, and now lots of people use it. Smiley
Logged
VolksBlade
I am totally NOT a...
Advanced Authority Member
*****
Offline Offline

Posts: 1067


WWW
« Reply #3 on: June 25, 2008, 11:34:09 AM »

heck yeah hes good..

@d3xt3r
hey man, dont forget in your XDD topic, or on the part of your site about XDD, to thank those who majorly helped in the development, such as; finding bugs, giving ideas, making add-ons, just to name a few..

not that i did any of those rolleyes ( cool )
Logged

Vanik's Book Spot
http://home-hacker.com/referral.php?id=221 <--My Hacker Referal Link
Do NOT Send Me A Message Unless If You Are A Friend Or I Ask You To
neostar
Hyper-Active Member
***
Offline Offline

Posts: 293


« Reply #4 on: July 13, 2008, 08:51:09 AM »

sorry for ruining the fun but it's 56kb, do you expect me to load 56kb each page?
Logged
d3xt3r
Guest
« Reply #5 on: July 13, 2008, 10:07:56 AM »

sorry for ruining the fun but it's 56kb, do you expect me to load 56kb each page?

Its 4 KB, and the require_once script is less than a Kilbyte I believe.. What are you referring to? XDD? That runs on server side and it doesn't load in the visitors browser, and provides many useful PHP functions.
Logged
uberwalla
Hyper-Active Member
***
Offline Offline

Posts: 476


WWW
« Reply #6 on: July 13, 2008, 10:18:41 AM »

I would recommend instead of

Code:
isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];

use just plain REMOTE_ADDR, otherwise people can use that to spoof their ip to anything.

Other than that, the script works really well. Thanks.
Logged
d3xt3r
Guest
« Reply #7 on: July 13, 2008, 10:35:18 AM »

I would recommend instead of

Code:
isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];

use just plain REMOTE_ADDR, otherwise people can use that to spoof their ip to anything.

Other than that, the script works really well. Thanks.

On 110mb that script is required for "www" addresses, since they run through a internal proxy. Wink Otherwise remote_addr shows the IP of the local server.

EDIT: However, I could write a bypass script, that would function the best of both.
Logged
uberwalla
Hyper-Active Member
***
Offline Offline

Posts: 476


WWW
« Reply #8 on: July 13, 2008, 10:39:47 AM »

it would be best if you could find it the person is using www, then use the forwarded ip, but use the remote mainly. Because all you need is a plugin for firefox (not gonna name it so no one gets any ideas of doing something) and you can edit the ip to spoof it to even text.
Logged
d3xt3r
Guest
« Reply #9 on: July 13, 2008, 11:55:52 AM »

To see if a person is using "www" without HTACCESS is only done in the same manner.. This is my thought...

This would work on Box4 to stop IP spoofing..And can be modified per box basis by changing IP..

Code:
if($_SERVER['REMOTE_ADDR'] == "195.242.99.89" && isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
else
$ip=$_SERVER['REMOTE_ADDR'];

This would only set the $ip to the forwarded_for IF remote_addr is the same as the Box your hosted on AND forwarded_for is set, otherwise, it would set it as remote_addr...

Smiley

Look good to you?

Get a current list of 110mb IP's here: http://d3xt3r.net/stats110/ - Left module dropdown
Logged
uberwalla
Hyper-Active Member
***
Offline Offline

Posts: 476


WWW
« Reply #10 on: July 13, 2008, 12:29:55 PM »

The only problem I see with this, which of course is still because of the internal proxy, would be that you can still spoof the forwarded ip if you go through it. So, basically if you go through the internal proxy, and spoof it, the real ip is still hidden. Of course not many people do this, so it wouldn't make a difference in the long run.
Logged
d3xt3r
Guest
« Reply #11 on: July 13, 2008, 12:32:33 PM »

The only problem I see with this, which of course is still because of the internal proxy, would be that you can still spoof the forwarded ip if you go through it. So, basically if you go through the internal proxy, and spoof it, the real ip is still hidden. Of course not many people do this, so it wouldn't make a difference in the long run.

However, when the HTACCESS proxies it, they use the REMOTE_ADDR and input the Forwarded For address. So in ending.. Its as secure as possible. Wink Posted a tutorial for it.. If you wanna check it out.. Its the last thread in Tutorials section.

But truthfully, the best way, as I pointed out in the tutorial, is to force non-www addresses and always use the Remote_addr if not using SymLinks in HTACCESS
Logged
neostar
Hyper-Active Member
***
Offline Offline

Posts: 293


« Reply #12 on: July 13, 2008, 07:45:51 PM »

ok, I'm sorry. didn't know it but it will take more time to get a response from the server?
Logged
d3xt3r
Guest
« Reply #13 on: July 14, 2008, 08:53:30 AM »

ok, I'm sorry. didn't know it but it will take more time to get a response from the server?

XDD on my system takes about .0001 seconds to process without any database operations.. Practically nothing..

Also, check the load time of my site.. http://d3xt3r.net/

Check the footer. shows the load time.. And its accessessing XDD all the time. a lot. with low process time.
Logged
neostar
Hyper-Active Member
***
Offline Offline

Posts: 293


« Reply #14 on: July 15, 2008, 07:12:56 AM »

wow, ok sorry again.

Off-topic

how can your website be only 479 days?
I remember there were a couple of problems with the servers.
Logged
d3xt3r
Guest
« Reply #15 on: July 15, 2008, 07:28:54 AM »

My website hasn't been "up" for a straight 479 days, that is from the time I setup the domain D3xt3r.net

I thought there might be confusion on that. However, I don't know another way to word my footer.
Logged
neostar
Hyper-Active Member
***
Offline Offline

Posts: 293


« Reply #16 on: July 15, 2008, 09:59:21 PM »

Off-Topic
have you ever thought creating a CMS that uses XDD?
Logged
Pages: [1]   Go Up
Send this topic | Print
Jump to: