473,242 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,242 software developers and data experts.

Web Stats With PHP?

Hey, I've never used PHP before. I was wondering if it is possible to use
PHP to generate web stats. My web host's stats aren't very good. So I
want to generate some custom stats for myself.

At a minimum, I want a log of the IP, referrer, environment variables, time
stamp, etc., and dump it into a comma delimited text file that I can import
into access or Excel. I don't need to generate gifs with PHP. Just need
the raw data.

Can PHP do this? My current understanding of PHP is that it is an embedded
language. I was hoping to execute a server-side script without having any
code embedded into the webpage. Maybe I could link to a PHP file?

I am currently using Go Daddy hosting--the $3.95/month package. It's nice
and cheap, but the stats aren't very good. I just basically want some raw
info that I can import and analyze as I need. I don't get raw data. Just
summaries.

With my package, Perl, CGI, and other tools are not available to me. I
only have the use of PHP.

So, any ideas of what I can do to generate some web stats? Any tutorials?
Free code? I've been looking, and I'm not finding a whole lot of newbie
info in this area.

Thanks.
Jul 17 '05 #1
8 5798
I'm not quite sure I understand exactly what you are trying to do. Do
you have access to the raw log files? It's very easy to convert the raw
log files into a csv. You may be able to simply replace all the spaces
with commas. If your stuck then give more details and I'll help you out.

Jul 17 '05 #2
It's possible - look into the global $_SERVER variable and some other
global variables ... read the beginning of the PHP manual (before the
function descriptions start)

Jul 17 '05 #3
"jdonnell" <ja********@gmail.com> wrote in news:1108710720.063981.108960
@l41g2000cwc.googlegroups.com:
I'm not quite sure I understand exactly what you are trying to do. Do
you have access to the raw log files? It's very easy to convert the raw
log files into a csv. You may be able to simply replace all the spaces
with commas. If your stuck then give more details and I'll help you out.

I do not have access to raw log files--that's why I want to create my own.
Go Daddy does not provide them unless you pay an extra $1.95 per month. If
I can easily do this on my own, why pay extra?

What I do have from my web host (Go Daddy) is a summary. It'll tell me I
got 42 hits yesterday, but won't tell me the IPs those hits came from. It
won't give times of the hits, or anything else of meaning.

What I get is a summary. It is nothing meaningful.

I want raw log files. I want to know that at 6:23 PM, someone from IP
xxx.xxx.xxx.xxx visited my site using IE 6, and was referred by Yahoo and
they are using a monitor with 800x600 resolution.

PHP is the only tool available to me with this hosting package. So, I'm
hoping to create my own raw stats.

This cheapo hosting package is everything I need right now--except for the
stats.

So if anyone can offer any guideance regarding this, I'd appreciate it.

Thank you.

Jul 17 '05 #4
Bob II wrote:

"jdonnell" <ja********@gmail.com> wrote in news:1108710720.063981.108960
@l41g2000cwc.googlegroups.com:
I'm not quite sure I understand exactly what you are trying to do. Do
you have access to the raw log files? It's very easy to convert the raw
log files into a csv. You may be able to simply replace all the spaces
with commas. If your stuck then give more details and I'll help you out.


I do not have access to raw log files--that's why I want to create my own.
Go Daddy does not provide them unless you pay an extra $1.95 per month. If
I can easily do this on my own, why pay extra?

What I do have from my web host (Go Daddy) is a summary. It'll tell me I
got 42 hits yesterday, but won't tell me the IPs those hits came from. It
won't give times of the hits, or anything else of meaning.

What I get is a summary. It is nothing meaningful.

I want raw log files. I want to know that at 6:23 PM, someone from IP
xxx.xxx.xxx.xxx visited my site using IE 6, and was referred by Yahoo and
they are using a monitor with 800x600 resolution.

PHP is the only tool available to me with this hosting package. So, I'm
hoping to create my own raw stats.

This cheapo hosting package is everything I need right now--except for the
stats.

So if anyone can offer any guideance regarding this, I'd appreciate it.

Thank you.


Bob,

You won't be able to get accurate stats without the raw log files. You
could put code at the start of each page to log information about that
page being loaded. But it won't be a true representation of your
traffic (i.e. images being downloaded, etc.) - just that page.

I ran into this a few months ago. Suddenly (over two days) I got about
a 20% increase in traffic for my favicon.ico. Other pages didn't show
this increase. I tracked it down to a site hotlinking to my
favicon.ico. A quick change and this site's IP was barred from
accessing any of my pages.

But I would have never found it without the Apache logs.

--

To reply, delete the 'x' from my email
Jerry Stuckle,
JDS Computer Training Corp.
js*******@attglobal.net
Member of Independent Computer Consultants Association - www.icca.org
Jul 17 '05 #5
" Go Daddy does not provide [raw logs] unless you pay an extra $1.95
per month."

I'd pay an extra $2/month.

If for some odd reason you don't want to then the easiest way to log
all of your traffic would be some mod_rewrite magic. You'd have to
check if they give you mod_rewrite capability because a lot of
free/dirt cheap hosts don't.

There are some hosts at reasonable prices that give you access to a lot
more than go daddy appears to. You can get an $8/month account with
lunarpages.com for example. I've used them a few times and they aren't
too bad.

Jul 17 '05 #6
Bob II wrote:
Hey, I've never used PHP before. I was wondering if it is possible to use
PHP to generate web stats. My web host's stats aren't very good. So I
want to generate some custom stats for myself.

At a minimum, I want a log of the IP, referrer, environment variables, time
stamp, etc., and dump it into a comma delimited text file that I can import
into access or Excel. I don't need to generate gifs with PHP. Just need
the raw data.

Can PHP do this? My current understanding of PHP is that it is an embedded
language. I was hoping to execute a server-side script without having any
code embedded into the webpage. Maybe I could link to a PHP file?

I am currently using Go Daddy hosting--the $3.95/month package. It's nice
and cheap, but the stats aren't very good. I just basically want some raw
info that I can import and analyze as I need. I don't get raw data. Just
summaries.

With my package, Perl, CGI, and other tools are not available to me. I
only have the use of PHP.

So, any ideas of what I can do to generate some web stats? Any tutorials?
Free code? I've been looking, and I'm not finding a whole lot of newbie
info in this area.

Thanks.

I use bbclone.. http://bbclone.de

Have done for years.

Jul 17 '05 #7
Bob II <he**@there.tv> wrote in
news:1108700375.9347916c4578683d24579eb003e8f3c7@t eranews:
Hey, I've never used PHP before. I was wondering if it is possible to
use PHP to generate web stats. My web host's stats aren't very good.
So I want to generate some custom stats for myself.

At a minimum, I want a log of the IP, referrer, environment variables,
time stamp, etc., and dump it into a comma delimited text file that I
can import into access or Excel. I don't need to generate gifs with
PHP. Just need the raw data.

Can PHP do this? My current understanding of PHP is that it is an
embedded language. I was hoping to execute a server-side script
without having any code embedded into the webpage. Maybe I could link
to a PHP file?


I'm a bit late to this thread, but I noticed talk had swayed to raw
access_logs. With PHP, you can get or reasonably estimate all of the info
you need to generate a simulated raw server log, which you could then
feed into any number of existing webstats apps, such as Webalizer. The
benefit here is that you'll get all the pretty charts and graphs and
hostname grouping and browser version grouping, etc. that a program like
this gives you.

Actually, this sounded like an interesting way to spend a few minutes, so
here you go, a raw log "faker":

<?php

#Open log file
if(!$fp = fopen('access.log', 'a')){
die('Unable to open access.log file for appending.');
}

#Build standard Apache-style log string
$username = (isset($_SERVER[PHP_AUTH_USER])) ? $_SERVER[PHP_AUTH_USER] :
'-';
$referer = (isset($_SERVER[HTTP_REFERER])) ? $_SERVER[HTTP_REFERER] :
'-';
$useragent = (isset($_SERVER[HTTP_USER_AGENT])) ? $_SERVER
[HTTP_USER_AGENT] : '-';

$entry = "$_SERVER[REMOTE_ADDR] - $username [" . date('d/M/Y:H:i:s O') .
'] "' . $_SERVER[REQUEST_METHOD] . ' ' . $_SERVER[REQUEST_URI] . ' ' .
$_SERVER[SERVER_PROTOCOL] . '" 200 ' . filesize(getcwd() . '/' . basename
($_SERVER[PHP_SELF])) . ' "' . $referer . '" "' . $useragent . "\"\n";

#Write log string to file
fwrite($fp, $entry);
?>

Put that code into a file named something like "logger.php" and create a
file named "access.log" in the same directory. Chmod the access.log file
to 777 (or "Owner RWX, Group RWX, World RWX") via your FTP app. Now, at
the top of your existing pages, insert this statement:

<?php include('logger.php'); ?>

If your files are currently .htm/.html, you may have to rename them to
..php for this to work, it depends on the server setup. Once everything is
set up properly, each visit to your pages will result in a new entry
being added to the "access.log" file. You can download this file
periodically and run it through something like Webalizer.

One caveat which was already pointed out is that this will only log hits
to your pages themselves, not hits to images, or any page that doesn't
use the include() statement. Another caveat is that the data size field
(i.e. the number of bytes that Apache sent to the remote user) is
estimated as the actual size of the file. AFAIK there's no way to pull
the real data, because while your script is running, Apache doesn't yet
know how big the output will be.

If you really want the CSV files, you can modify the code above so that
it prints out the right values, but with commas between them instead of
the Apache log formatting.

hth

--

Bulworth : PHP/MySQL/Unix | Email : str_rot13('f@fung.arg');
--------------------------|---------------------------------
<http://www.phplabs.com/> | PHP scripts, webmaster resources
Jul 17 '05 #8
On Fri, 18 Feb 2005 04:19:34 GMT, Bob II <he**@there.tv> reverently
intoned upon the aether:
Hey, I've never used PHP before. I was wondering if it is possible to use
PHP to generate web stats. My web host's stats aren't very good. So I
want to generate some custom stats for myself.

At a minimum, I want a log of the IP, referrer, environment variables, time
stamp, etc., and dump it into a comma delimited text file that I can import
into access or Excel. I don't need to generate gifs with PHP. Just need
the raw data.

Can PHP do this? My current understanding of PHP is that it is an embedded
language. I was hoping to execute a server-side script without having any
code embedded into the webpage. Maybe I could link to a PHP file?

I am currently using Go Daddy hosting--the $3.95/month package. It's nice
and cheap, but the stats aren't very good. I just basically want some raw
info that I can import and analyze as I need. I don't get raw data. Just
summaries.

With my package, Perl, CGI, and other tools are not available to me. I
only have the use of PHP.

So, any ideas of what I can do to generate some web stats? Any tutorials?
Free code? I've been looking, and I'm not finding a whole lot of newbie
info in this area.

Thanks.


Create a demo page and add the following:

<pre>
<?php
print_r($GLOBALS);
?>
</pre>

This will print everything you have available to you ($_SERVER, $_ENV,
$_GET, and etcetera are in $GLOBALS). Now if you want to go past
that, then you will need to use client side JavaScript or something
similar to pass to you some additional values (client screen
resolution, and other such). But much of what you can get from
Javascript really only has value in aggregate anyway (statistics from
small samples are rarely representative).

Anyway, $GLOBALS and MySQL will get you started.

have fun,

Sean
"In the End, we will remember not the words of our enemies,
but the silence of our friends."

- Martin Luther King Jr. (1929-1968)

Photo Archive @ http://www.tearnet.com/Sean
Last Updated 29 Sept. 2004
Jul 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: mr_burns | last post by:
hi, i want to put some useful marketing stats onto a web site but cant really think of many. ones that i have thought of that would be useful for marketing are: - which URL did a user come...
0
by: dba | last post by:
Hi I am a new MySQL dba tuning a busy Apache/MySQL installation. Here are some of the statistics for the last 24 hours: Com_admin_commands 978,760 What "Admin_Commands" does this...
1
by: Peter Sands | last post by:
Hi, I am trying to run an update stats command but keep getting a syntax error: Looking at the doco it looks like I can use: update stats <table_name>; but when I use: mysql> update stats...
5
by: Peter Jenkins | last post by:
The client for which I do this site www.safenz.org.nz wants stats tracking/a visitor counter, like the one that is there at the moment (at the bottom of the home page). However I would like one...
0
by: Utter Newbie | last post by:
I know we have access to log files and web statistics can be pulled from those. But the guy who wants it built was thinking we should keep track of every time a page is hit seperately in MS sql...
0
by: JohnZing | last post by:
hi I made a simple web page Stats.aspx To get visitiors information for all my websites. In my websites i use <img src="http://stats.xxxxxxx.com/stats.aspx?site=yyyy> This works ok. The...
1
by: MKoool | last post by:
Is there any decent library for basic stats? I am just looking for the basics, like quartiles, median, standard deviation, mean, min, max, regression, etc. I was going to use SciPy, but I use...
9
by: ankitdesai | last post by:
I would like to parse a couple of tables within an individual player's SHTML page. For example, I would like to get the "Actual Pitching Statistics" and the "Translated Pitching Statistics"...
2
by: Monu | last post by:
HI All, I am getting problem in using hotshot profiler. When I hotshot with lineevents=0, it works fine, but when I use lineevents=1, I get error in stats here is my code: import hotshot,...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.