Help - Search - Members - Calendar
Full Version: Statistics
HTMLHelp Forums > Web Authoring > Web Site Functionality
wacssabe
Hi, i didn't find any thread related to my question :-(. Well, i want to put a visits counter on my webpage, as well as one resolution, user-agent, browser, how came to my web (by searching the word/s "InsertWord/s", their operative system, and so on) tracker. I tried this by php, and js, but as they work on different sides, they can't communicate. I don't know anything about server/client languages, just raw html and css. I know some statistics tracker can log all this data, and i was just about to apply for one of them, when i read that they'll include my web at their database to make hitlists and several things i don't want to. I want my page anonymous, just to appear at google and other search engines.

I don't like cookies, and i don't use them at my page. I'd like not to depend on external services to track these numbers, just log them to a text file at my host. But i won't care if using them is needed. What i really don't want, is my web at lists, and those things. So, do you know any "just keep doing what i asked for" statistics tracker? (Preferrably, without inserting directly ads on the page. I don't mind if they are in the statistics page). Many thanks in advance, i searched a copule of hours and didn't find many help sad.gif.
pandy
How are you hosted? Do they give you access to your request logs? If so, that's all you need. The server logs and a program that can analyze them.
Darin McGrew
Perhaps one of these CGI or PHP stats programs will meet your needs:
http://cgi.resourceindex.com/Programs_and_...and_Statistics/
http://php.resourceindex.com/Complete_Scri...and_Statistics/
wacssabe
HI smile.gif. I've read about using phpinfo() to list php properties. I've decided to use for now my university's web service until i find a better one. There are many tabules, with things as linux version, apache, and many others. One of those things (several times repeated at different points) is my user agent, o.s., and a little more. I want to know that, but resolution too (it isn't shown).

Anyway, isn't php suposed to be server side? Why does it log data about the user?

I have no problem to post the url, but first i need that someone tell me if revealing that data would be unsafe for my university. Here are the captions of the data tables: php variables, tokenizer, xml, environment, standard, sqlite, spl, simplexml, session, reflection, pdo, sqlite, pcre, json, libxml, filter, date, http response headers, http request headers, apache environment, apache2handler, phpcore, system, build date, configure command, server api, ... registered strem filters.

Pandy i don't know what you mean by how i am hosted. To upload my page i must put it in a web directory in my home drive.
Then i go to server.com/myhome/index.(html/php/xml).

I'll try to do it this way so i don't need external services, but if resolution can't be logged this way, i'll have to do it with them.

Thanks.
Darin McGrew
QUOTE
Anyway, isn't php suposed to be server side? Why does it log data about the user?
The browser sends a user-agent string, and the server-side program guesses from that. Of course, the user-agent string isn't reliable:
http://webtips.dan.info/brand-x/useragent.html
wacssabe
Thanks Darin, the link helped a lot, now i understand how user agent strings work with server side languages. However, i can't figure out how stats trackers know the screen resolution of the user. It isn't mentioned in the string. Where's the clue?
Darin McGrew
I think there's JavaScript that can look up the screen resolution. Of course, what really matters is the size of the browser window. (I never use full-screen browser windows except on my mobile device.)
pandy
Normally every request to the server is logged. A proper host usually gives you access to your own log files so you can download them and analyze them or do it on the server. My guess is the uni server don't give you the log files.

If you are interested in stats and look for other hosting later, make sure the specs include "raw logs". The logs grow enormous, for a page like this there's maybe 50 lines in the log file each time it's requested (many small images), so some hosts prefer not to save the logs.

They won't tell you about resolution and such, you already know that. Typically you get IP, useragent, referrer, the server's response code and a time stamp.
wacssabe
Yeah, i supose they don't, given that i only got a 300 mb partition for all my documents. But I know that phpinfo gives a lot of info when i access my web (it tells my user agent string, some apache i don't know tells my user agent string too, and many more things like time), so could i write a program to take that lines in real time and simply work with them? I mean (in c)
CODE

char string[80], string2[20],string3[20],string4[20];
pf*=phpfile;
pm*=mystatsfile;
fopen(pf, "r");
fscanf(pf,string);
while(strcmp(string, "user-agent")!=1)
   fscanf(pf,string);
for(int i=0, j=0;string[i]!='.';i++;){
   string[i]=fgetchar(pf);
   if(string[i]=' '){
      j=i;
      fseek(string, i-j, SEEK_CUR);
      sscanf(string, string2);
      if(strncmp(string2,7,"firefox")){
         fopen(pm, "r+");
         fscanf(pm,string3);
         while(strcmp(string3,"firefox")!=1)
         fscanf(pm,string3);
         fscanf(pm, & int k);
         fprintf(pm,"%c%d", \backspace, k++);
         fclose(pm);
      }
      else if(strncmp(string2,5,"opera")){
         fopen(pm, "r+");
         fscanf(pm,string3);
         while(strcmp(string3,"opera")!=1)
         fscanf(pm,string3);
         fscanf(pm, & int k);
         fprintf(pm,"%c%d", \backspace, k++);
         fclose(pm);
      }
      else if(strncmp(string2, 4, "msie")){
         fopen(pm, "r+");
         fscanf(pm,string3);
         while(strcmp(string3,"IE")!=1)
         fscanf(pm,string3);
         fscanf(pm, & int k);
         fprintf(pm,"%c%d", \backspace, k++);
         fclose(pm);
      }
      else{
         fopen(pm, "r+");
         fscanf(pm,string3);
         while(strcmp(string3,"Unknown")!=1)
         fscanf(pm,string3);
         fscanf(pm, & int k);
         fprintf(pm,"%c%d", \backspace, k++);
         fclose(pm);
   }
}


The same could go for operating system, user agent, time, referer, i'm really interested, etc.
wacssabe
Hi, for starters i'm learning php, and just to make a try, i wrote this
CODE

<?php
$mylog = "./logs/stringsvisitors.txt";
$fh;
if(($fh = fopen($mylog, 'a')){
    fwrite($fh, phpinfo());
    fclose($fh);
}
else{
    echo phpinfo();
}
?>


But it won't work. I thought that if php script is loaded each time a user goes to the page, php info will have the info of that user, and if as i read phpinfo returns the whole info, when i use fwrite($fh, phpinfo()); it should get logged there. Instead, i get my page in blank and no log file is created, and no info is either apended if it's yet creted.

Do you have any idea?.
Brian Chandler
phpinfo() writes the info to output -- it's so you can make a check page to show you everything, as an html page. Here's my (complete) file:

CODE

<? //phpinfo.php

phpinfo();

?>


See: http://jp2.php.net/manual/en/function.phpinfo.php

But anyway, just write your program to log the information you are interested in, which will typically be a few variables. If it helps, here's my own error logging function, which writes the message together with some user info:

CODE

function errlog($msg)    // writes error with referrer etc. (new file each month)
{    $mm=date("n");    // this month (1 - 12)
    $absfile = $_SERVER["DOCUMENT_ROOT"] . "/shop/admin/err$mm.txt";
    $log = fopen($absfile, "a");
    flock($log, LOCK_EX);
    fwrite($log, jtime() . " JST *** $msg\n");
    fwrite($log, $_SERVER["REQUEST_URI"]);
    if ($_SERVER["HTTP_REFERER"])
        fwrite($log, " from " . $_SERVER["HTTP_REFERER"]);
    fwrite($log, "\n" . $_SERVER["HTTP_USER_AGENT"] . "\n\n");
    flock($log, LOCK_UN);
}
wacssabe
Hmmm i think i got it. Thanks Brian. Php is a script that works on our html code, and phpinfo() just tells php send a kind of (pseudocode) <div> <table1>row1col1,row1col2,..</table> <table2>...</table2> + MyHtml code = the page users see. Right? In the other hand, there's real php variables as $_SERVER["REQUEST_URI"] that can be logged into a file.

If i am right, then all i have to do is choose which strings i need and set the php script to log them each time somebody access my page.

Aside from my question, i wonder how big websites whith loads of people accessing them simultaneosly (not actually simultaneous, but supposing a delay minor than the time that opening a file, writing and closing it takes for a computer) do process al that visits data to keep them all? Do they use many temporary files and a lot of memory or what?

I've recently discovered that i can make my own server on my computer, and that i had apache web server preinstalled, but php wasn't enabled. After changing a couple of things it was enabled and worked, but now i've changed the DocumentRoot and Directoy and surely another file, because even settings documentroot and directory to "/~" my files at home won't load. If i manage to repair it i'll try php at my computer so i haven't restrictions.
Frederiek
The phpinfo() function simply ouputs information about the current state of PHP. See http://us.php.net/phpinfo.

Sorry, I can't really help you on what you try to achieve, as I'm myself rather new to PHP.

Haven't you noticed that on some big sites pages take a long time to load, at each call to the (MySQL) server? Even Google was down yesterday after the info that Micheal Jackson had died.

Are you on Mac or PC? On Mac, PHP is installed with the Apache server.
Try to find a package for your OS that installs PHP or reinstalls both Apache and PHP.
wacssabe
Hi Fred, my computer is a mac (leopard) and apache and php are yet installed and enabled now, but i have some problems changing the index.php directory, because i edited some keys and now i don't know. I've set correctly DocumentRoot and Directory keys to "~", but there must be another because it sticks opening in ~/sites (a folder for personal websites in each user home). I'll keep looking for a solution to my index directory problem. And yes i noticed too google particularly slow yesterday, but my isp sucks anyway so i can never tell who's the responsible for those lapses.

Long live mike!
wacssabe
repeated :S
Brian Chandler
QUOTE(wacssabe @ Jun 27 2009, 07:15 PM) *

Hmmm i think i got it. Thanks Brian. Php is a script that works on our html code, and phpinfo() just tells php send a kind of (pseudocode) <div> <table1>row1col1,row1col2,..</table> <table2>...</table2> + MyHtml code = the page users see. Right? In the other hand, there's real php variables as $_SERVER["REQUEST_URI"] that can be logged into a file.


Just to niggle a bit... PHP is a programming language (not really a very good one from a theoretical perspective, but very widely used for web scripting); there is a program called the PHP interpreter that reads PHP programs and executes them. Usually it's reading a (php) web page, and carrying out all the instructions inside <? ?>, while just passing outside text directly to the web server.

phpinfo() is a php *function*. Your program calls it, and the function does (precisely) what the manual tells you. No more no less. If you hoped it would realise you really meant to say something slightly different, well, it won't. So learn to use the online manual, which is generally very good.

These "server variables" -- there are lots of them -- are values your program can access, and do what it likes with -- log to a file, output in a table, popup window, iframe, javascript terribly clever trick, whatever.

QUOTE

Aside from my question, i wonder how big websites whith loads of people accessing them simultaneosly (not actually simultaneous, but supposing a delay minor than the time that opening a file, writing and closing it takes for a computer) do process al that visits data to keep them all? Do they use many temporary files and a lot of memory or what?


Who knows. A basic thing to realise about log files is that you need to lock them (as in my example) in case two copies of your program happen to run at the same time. The basic Unix(-like) filing system does not do this for you. The good news is that databases (MySQL etc) _do_ handle all the locking for you, so as long as you updates in a single SQL command you know they will not mess up.

A good general read about this is the book on this page: http://imaginatorium.org/stuff/pagwp.htm



wacssabe
I could swear i read anywhere that phpinfo() did return the whole info in a string ! Well sorry, i went to the web but forgot reading about phpinfo as i was interested too in a printf like function. I've realised php is really simmilar to C, so it's very easy for me. As for sql, i have many things to learn before i go to sql language happy.gif. I haven't solved yet the php problem, i'ts driving me crazy because anywhere it says that the only actions to change index directory is editing those 2 keys at /private/etc/apache2/httpd.conf
I've even replaced the file for the httpd.conf at /private/etc/apache2/original/ and edited the 2 keys again, but still doesn't work. Maybe it has to do with the OS, because to activate the server i must active a "web sharing" option, which points the web to http://myip.dyn.user.myisp.com/~myuser/, its a strange route, i'll keep trying. Thanks again.

Reading the httpd.conf there's a note i can't understand:
QUOTE
Configuration and logfile names: If the filenames you specify for many
# of the server's control files begin with "/" (or "drive:/" for Win32), the
# server will use that explicit path. If the filenames do *not* begin
# with "/", the value of ServerRoot is prepended -- so "/private/var/log/apache2/foo_log"
# with ServerRoot set to "/usr" will be interpreted by the
# server as "/usr//private/var/log/apache2/foo_log".


If that is right, the double slash wouldn't have to appear at all because the foo_log path do has been typed with a leading slash. Why the second bar? This is quite confusing, because i read about relative urls, double slashes at http:// and i've even seen anywhere three slashes :S:S.
Frederiek
On Mac, you should put your files for the server (http://localhost) in the folder at:
Macintosh HD > Library > Webserver > Documents
I'm still on Tiger (I'm waiting for Snow Leopard), but I suppose it works the same on Leopard.

You need to set "Sharing Mac files" and "Sharing personal web" in Sharing preference of the System Preferences.

You then access those files at http://localhost/file_name.

AFAIK, you don't need to change any config files to run a localhost. I never did.

Here you'll find a PHP module installer package for the Apache web server included in Mac OS X:
http://www.entropy.ch/software/macosx/php/

Or use XAMPP, which includes an Apache 2 web server, integrated with the latest builds of MySQL, PHP (both 4 and 5) and Perl.
http://www.apachefriends.org/en/xampp-macosx.html

If you don't want to start with MySQL, you can always turn to SQLite (http://www.sqlite.org/), which is similar but easier (without the fuzz of logins).
wacssabe
Many thanks Fred. That's where they worked for me, but i'd like to change the localhost directory. That' why i edited the httpd.conf DocumentRoot to "~" and the main directory to <Directory "~">, so when i place my index.php + files at my home folder and turn on the web sharing (i'm concerned about rebooting web sharing each time i edit apache config), they should work. But they don't. Searching on the web, i found this link which shows where should things be in each OS and apache version. Even rendering all settings to default by copying the backup copy of httpd.conf at /private/etc/apache2/original, the only way it works is by putting my web at the folder you say. But i want them to be in my desktop. I dont know why DocuementRoot "~" and <Directory "~"> won't work, even using "/Users/myuser" or "/Users/home". While reading the comments at httpd.conf i saw
QUOTE
Configuration and logfile names: If the filenames you specify for many
# of the server's control files begin with "/" (or "drive:/" for Win32), the
# server will use that explicit path. If the filenames do *not* begin
# with "/", the value of ServerRoot is prepended -- so "/private/var/log/apache2/foo_log"
# with ServerRoot set to "/usr" will be interpreted by the
# server as "/usr//private/var/log/apache2/foo_log".
.

This confuses me too, because /us//private... shouldn't work because of the double slash, but in http: we actually put them, and also i've read somewhere nfs or smb:/// (three slashes!). There should be /usr/private... and as the comments say, /private/var... has the leading slash, so the absolute route shouldn't have to add the extra bar to /usr, but conversely to what the comments say ("if the filenames you specify ... begin with / the server will use that explicit path"). So i'm really confused.

And in addition, i'm too confused with user www and group www, what are them meant to be? I've read so many pages, the apache help and many others but no one is of help for me :-/.

About XAMP i read about a simmilar tool (mamp). Maybe when i know how to make it this way i get it, but for now i want to learn, more than making it work. But thanks. About sql, i'll take a time before going on with databases. I first must learn languages like python, java, and more things i got in mind mellow.gif .

Added: WOW! I have just discovered a different section here at htmlhelp where php and many other programming languages are discussed. I thought web-functionality was about this, but now i think this belongs there. I'll put this link here so if anyone wants follow the thread have a shortcut.

Thanks all.
Frederiek
QUOTE
That's where they worked for me, but i'd like to change the localhost directory

Why? What's wrong with having to type localhost and to go to your index page? Personally, I'd rather not mess with things like that, when all I want is do some PHP tests for a learning experience.

I put the folder Documents (of the Webserver folder) in the Finder's window side bar. So with two clicks, I get to my server files.

User and Groups have to do with permissions. See http://en.wikipedia.org/wiki/File_system_permissions
You access these at the bottom of the Info dialog (Command-I on a file or folder).

I used to use XAMP and looked into MAMP too. Now I don't use either anymore. But both help to get it all installed correctly.

There was no need to start another thread on the same topic. If moderators feel a thread rather belongs in another sub-forum, they will move it there for you.

Anyway, I don't think I can help you any further. So, good look.
pandy
QUOTE(wacssabe @ Jun 28 2009, 01:29 PM) *

Many thanks Fred. That's where they worked for me, but i'd like to change the localhost directory. That' why i edited the httpd.conf DocumentRoot to "~"


You are supposed to put the path to the the folder you want to function as document root there.
wacssabe
Hi first if any mod thinks this is a better place feel free to remove the other thread.

Fred thanks for explaining the user group info, as i understood it, they are a new user / grupo created by apache or the OS so i can specifically set permissions to apache for the files it handles. However when i look a file permissions with command+i, i only see "system/wheel/everyone", and in my desktop i see folders and files with "myuser(me)/staff/everyone", and i think i've seen anywhere "others" too. What i mean: the www user and www group aren't in my apache files permissions list, so i can't tell which rights they have. And the "everybody" user makes me think that even though visitors have denied access by www apache user, the everybody user might let them edit the files if "everybody" means what it seems. Browsing i found that all users are in passwd, altought it tells
QUOTE

Note that this file is consulted directly only when the system is running
# in single-user mode. At other times this information is provided by
# Open Directory.


I couldn't find any open directory file.

At passwd the www line is

QUOTE

_www:*:70:70:World Wide Web Server:/Library/WebServer:/usr/bin/false


Everybody isn't listed there :-(

I don't know about permissions though, just that -r means read, and so on.

No problem if you can't help more, thanks again.

Pandy, i've already done that but it simply doesn't like me :-(. Also, although in the specific o.s./apache 2.2 link i posted before it says serverroot must be /usr for mine, in user there isn't any apache folder, just bin, include, lib, libexec, local, sbin, share, standalone, texbin, x11, x11R6 folders, and there's nothing inside them with apache names. Maybe those are the files apache take, but at /private/etc/apache2 there's a lot of apache files, maybe the serverrot is that folder.

Well, i know this is really specific but if you anyone does know anything about this, please say it. Thanks.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.