Sponsored by Best Buy
Best Buy casts another employee in holiday campaign. view!
youtube.com/bestbuy0 - Jarice Brodie has done some cool things in his life. Next: Best Buy’s holiday campaign.
58 Comments
- droplister, on 06/17/2009, -1/+38Google Analytics, Awstats, Webalizer. I don't care how they work, they work. And when they break someone else fixes it.
- bradleyland, on 06/17/2009, -0/+23This is an asinine tutorial. The author uses AJAX to post back data that is part of the $_SERVER collection. This is like mailing yourself a letter!
A PHP script only runs when requested, so there is no reason you couldn't run these scripts as part of a page request. The $_SERVER collection is available as part of your *server* based PHP scripts. Duh. All this does is form an unnecessary HTTP request to your web server.
To use this without the extraneous AJAX *****, replace these lines:
# Obtain the necessary information the stupid way
$page = $_POST['page'];
$referrer = $_POST['referrer'];
$ip = $_SERVER['REMOTE_ADDR'];
# Obtain the necessary information
$page = $_SERVER['REQUEST_URI'];
$referrer = $_SERVER['HTTP_REFERER'];
$ip = $_SERVER['REMOTE_ADDR'];
Then ditch the AJAX ***** from your HTML page and drop in a require_once() with the path to process.php.
EDIT: Ok, so I just read the end and realized the author is a high school student and I feel bad. Karthik Viswanathan, nice work, but keep learning and you'll be a great programmer. - merreborn, on 06/17/2009, -0/+22While this example might be enough for a novice to pick a few things up from...
1) It's of no practical value
2) It fails to acknowledge just how little it does, and how much more work it takes to get from there to a real analytics package (this doesn't even implement 1% of the functionality in awstats, let alone google analytics)
3) Using xmlhttprequest for tracking is so braindead, it hurts. There are plenty of browsers it won't work in.
4) Identifying users only by IP? What is this, 1994? Set a cookie, for christ's sake -- one user may visit from several IPs; one IP may be shared by several users.
I could go on... - masonentingh, on 06/17/2009, -0/+18Yeah you know C
- jkroge, on 06/17/2009, -2/+14Thanks, but I have better things to do with my time besides reinventing the wheel. Google Analytics and Awstats work just fine.
- tama00, on 06/17/2009, -0/+11Upvoted because you dont need AJAX or even javascript for that matter if you are doing your own stats program.
- Yggdrasil, on 06/17/2009, -0/+11This code has a XSS vulnerability in it.
- kalvinb, on 06/17/2009, -0/+6JavaScript has access to the referer and requested URL: document.location and document.referer
You also don't need to use AJAX
http://blog.dawnofthegeeks.com/2009/06/16/using-ja ...
JavaScript can be used to import a JavaScript file (the PHP, .Net, whatever, script that does the logging) with all the data you want attached to it. The logging file doesn't output anything so the browser just thinks it got an empty js file which doesn't cause any errors.
To then track visitors on any site I just put
-SCRIPT LANGUAGE="JavaScript" SRC="http://js.dawnofthegeeks.com/log.js"- -/SCRIPT-
on the page. One line. And if I want to log more information I just edit the log.js file and don't have to go through all the individual sites. - inactive, on 06/17/2009, -0/+5too late!
- mecharabbit, on 06/17/2009, -3/+8You down with PHP?
- zephc, on 06/17/2009, -0/+4why bother when there is better stuff out there already?
step 1: use google analytics
step 2: analyze your logs
step 3: adjust website
step 4: profit!!! - merreborn, on 06/17/2009, -0/+4Awstats has way more features, and it's open source, if you want to customize it.
- brianez21, on 06/17/2009, -0/+4Looks like it has already been exploited by ha.ckers.org... I'm getting one of those javascript alert dialogs when I view the demo stats page.
- droplister, on 06/17/2009, -1/+5Dear Mr. Logic,
By using a service--any service, take Digg for example, you are depending on someone else. When you live on an island, in a shack built by your own two hands, powered by hopes and dreams, depending solely on yourself, then come and lecture me.
Until then,
Dan Anderson
"No man is an island." - John Donne - scalded, on 06/17/2009, -0/+4He's actually better off using XMLHttpRequest if he's seriously running sqlite write operations with every page request. There's going to be a delay as the server tries to get a lock on the db file, browser performance is obviously no concern and he can afford to lose the tracker requests.
"Karthik Viswanathan is a high-school student who loves to program and create websites"
Credentials of a seasoned PHP developer. - inactive, on 06/17/2009, -0/+3I actually specialize in making service based apps like this.
While doing this type of thing may seem mundane (I see a lot of 'just use Google or AWStats'), there's a lot of info you can use to optimize your site that they don't provide.
For example, if you make a specific blog post, or run a store and have a certain promotion, how it affects traffic, how visitors interact with your site, and so on.
Writing something like this on your own is definitely worth checking out since everyone has different neds, and if you use the data the right way and form your site accordingly, you'd be surprised at the amount of increased and sustained traffic you get. - JackT, on 06/17/2009, -0/+3What ever happened to reading raw logs from the web server?
- wavesmachine, on 06/17/2009, -0/+3Dugg for being a tech article on the front page.
- m3xican, on 06/17/2009, -0/+3Using a DB and doing the math with PHP is very smart... BURIED
- inactive, on 06/17/2009, -0/+2Because that's where innovation comes from.
- Deepmist, on 06/17/2009, -0/+2Anyone who has javascript turned off, ie many company computers.
- kalvinb, on 06/17/2009, -0/+1Doing it yourself gets you access to the raw information and allows you to write the specific reports and views the way you want them. You can also get consistent logging data regardless of the server the sites are using. IIS and Apache log two different (similar, but different) ways.
I use it as an alternative to logging with Apache/IIS which slows down the server response time and just ends up killing harddrives for no good reason. I let GoDaddy deal with the asyncronous logging while my sites run on whatever server I want them on.
Of course the downside is, now you don't get any information from people who don't have JS enabled.
There is practical value. Just not for most people. Most people don't run two types of web-servers. And most people don't run a bunch of web-sites. - Atheizt, on 06/17/2009, -0/+1wtf as the government got to do with anything?
- paradigmxx, on 06/17/2009, -0/+11. Use Google Analytics
2. Track your paths
3. Cut out unnecessary traffic costing $
4. ???
5. PROFIT! - kalvinb, on 06/17/2009, -0/+1Not every host has logs. GoDaddy has logs available if you turn them on but it's a pain to have to download them just to process them. By having everything already in a database you can more easily write reports and see activity in real time.
- theblt, on 06/17/2009, -0/+1Sure, that's cute if all you want are "hits"...
But what the CLIENT wants is detailed revenue reports, conversion success, path reports, I could go on. You're never going get that with a home rolled analytics package -- that is of course unless you reinvent Mint, Google Analytics, or Omniture. - Deepmist, on 06/17/2009, -0/+1For those of you who haven't noticed yet, it's written by a high school kid. Might want to take that into consideration.
- jsp123, on 06/17/2009, -0/+1Dang was just typing my post and saw your post right above the box... http://piwik.org/ for people as lazy as me :)
- zephc, on 06/17/2009, -0/+1Real-time reports don't matter unless youre getting DDoS'ed
- TexasMd91, on 06/17/2009, -3/+4Good thing everyone doesn't have that logic... we would be in some deep ***** if everyone depended solely on everyone else
- kenplaysviola, on 06/17/2009, -0/+1Besides Google Analytics, I also like the open-source Piwik. It's runs on PHP with MySQL and is easy to use. Just copy/paste the Piwik javascript code into your website and you can log into your Piwik server to get stats.
- tgc1, on 06/17/2009, -0/+1Just read your logs.
- merreborn, on 06/17/2009, -0/+1If you look at real analytics packages, like google analytics, they don't use XMLHttpRequest. They insert a tracking pixel into the page.
Any browser that supports javascript supports tracking pixels. Not all browsers that support JS support XMLHttpRequest. - merreborn, on 06/17/2009, -0/+1You're absolutely right about all the advantages, but you can get all of that and so much more with a commercial logging package like Urchin.
- chmpdog, on 06/17/2009, -1/+2why reinvent the wheel?
- NeoDreamer, on 06/17/2009, -0/+1How would you convert the IP address to a location? (Any FREE ways to do this?)
- merreborn, on 06/17/2009, -0/+1Anything released before 2002, and any non-mainstream browsers (e.g., browsers designed to be accessible to those with disabilities)
Granted, generally, those are less important, but when it comes to analytics, you want to be able to track *every* hit. - jamesbtaylor, on 06/17/2009, -0/+1well it depends... you need JS if you want to detect client parameters like screen resolution and stuff like that
- knotboy, on 06/17/2009, -0/+1Dude, I clicked your profile and I am laughing my ass off. Your comments are funny as hell. Good job!
- NeoDreamer, on 06/17/2009, -0/+1Ah, very clever!
It kind of relies on that site being responsive, though. - calebrown, on 06/17/2009, -0/+1I needed to do this for a project I worked on recently, using PHP I did file_get_contents on this URL: http://ws.arin.net/whois/?queryinput=$_SERVER['REM ... and parsed the data. Not 100% accurate, but it's free.
- mikemehak, on 06/17/2009, -1/+1The only thing more exciting that statistics is making statistics programs with Java
- kristinaduff, on 06/19/2009, -0/+0Holy *****,
Such a silly tutorial popped on digg... WTF!!! It seems like no intelligent people are left here on digg... apart from basic sql injection issues there are a hell lot of issues in this screwing tutorials..
God Bless the Diggers !!! - inactive, on 06/17/2009, -1/+1It's a big brother joke....... I think.
- jamesbtaylor, on 06/17/2009, -0/+0oh come on, what's wrong with high school kids? I built a stat system several times better than that at the age of sixteen :)
- KSUdesigner, on 06/17/2009, -4/+4Some people find it interesting, myself included. If you don't care then move along, nobody said you had to code a stats program.
- jamesbtaylor, on 06/17/2009, -0/+0has anyone else noticed how this particular approach is so vulnerable to SQL injection?
- kristinaduff, on 06/19/2009, -0/+0Use GeoIPDatabase... its the best way to convert IP to the location... have a look at awstats geoip plugin ... it uses geoip database(it is free)..
-
Show 51 - 63 of 63 discussions


What is Digg?
Browsing Digg on your phone just got easier with our enhancements to the