Home
Home Page
Processing of tags html in TextField
Web 2.0 for designers
That in exchange
Keshirovanie registrations
Semantic web. A note about logical and illogical imposition
XHTML, speak?
Lessons of ASP-technologies
Often asked questions (FAQ) about ASP
Complex  regular expressions
Receptions of network defense on PHP
Receptions of network defense on PHP - 2
Development objective orientirovannosti PHP
Banner business
Use Output Buffering in PHP
Use Output Buffering in PHP
Doloj procedural programming, you allow object-oriented!
How to learn{find out}, whence there came visitors
Links


How to learn{find out}, whence there came visitors

Having hung up on the site I suddenly have found out counters, what not one of the organizations, me their given, does not allow to see, on what search in a Yandex (and others poiskovikakh) this or that person has come on my site. At least, nobody renders such service free-of-charge.


Then I have taken offence at them that I, in that case, should write itself to myself small logger. Zadachka - the easiest therefore broke her  to do{make}. However owners of any sites - schjotchikov have the nerve to take for it of money, installing in people belief, that the money burt knowingly. Well, razveem their hopes of us poimet`!

Page from which came


So, to receive page from which the user has got on this, - it is easier easy. Its{her} address is by default passed in heading of HTTP-search of the user in line " Referrer: ". To receive its{her} value from PHP it is possible, having called corresponding function as follows:

getenv ("HTTP_REFERER")



So, basically, it is possible to take and write simply separate function, which:

$H=getenv ("HTTP_REFERER"); // receives URL from which there has come the visitor


$f=fopen ("mylog.log", ' a '); // opens a file with broad gullies on addition


flock ($f, 2); // forbids to it  access until then,


                   // While he will not be closed (in case two


                   // A script will want simultaneously to write down something


                   // In a file, one of them should wait)


fwrite ($f, "$H\n"); // writes to a file received by three lines above URL


fclose ($f); // closes a file



Then this function can be caused in the beginning kakzhdogo a php-script of pages of a site.

How to learn{find out} ip, the destiny and an exact times


But! Time we here, it is possible to finish a little function to learn{find out} IP the visitor (on it  it is possible to estimate approximately area, where he is physically), his  browser (interestingly) and a page, where he, has actually come (sounds a little strange - we and so we know, that he has come on our page; but present, that this function is caused in you in a site of a heading code which is equally inserted into all your pages, - and so, perhaps, you and will make). Also not bad to have time when chel has come to us on a site - then it will be possible to analyse activity of users, etc.


So, function will accept the following kind:

$er_time=date (" H:i:s d M Y "); // it is written down current time at line,


    // Using the set format


$U=getenv ("HTTP_USER_AGENT"); // we obtain the data on a software,


    // Which ispol`uet the user


$H=getenv ("HTTP_REFERER"); // it is received URL from which there has come the visitor


$R=getenv ("REMOTE_ADDR"); // it is received IP the visitor


$W=getenv ("REQUEST_URI"); // the relative address of a page is received,


    // Which was requested by the visitor


$f=fopen ("logs/visits.log", ' a '); // is farther - understandably, we write all this to a file


flock ($f, 2);


fwrite ($f, " $er_time\n Br: $U\n Rf: $H\n IP: $R\n Rq: $W\n ");


fclose ($f);



But also this function is far from perfect! The matter is that you in these urlakh will not see Russian symbols - them will replace them 16-richnye performances (anticipated it is familiar "%"). Therefore it is quite good that the script independently resulted them in a legible kind: replaced everyones

http: // www.yandex.ru/yandsearch? text = % E9%EE%E6%FB%E3 + % F4%F2%F3%EC%E0%ED%E5*stype=www



On

http: // www.yandex.ru/yandsearch? text=®«ªHH``+khFT¼b¡S*stype=www



We we shall do{make} is by the following piece of a code with use of regular expressions:

while (ereg (' % ([0-9A-F] {2}) ', $H)) {// while in line $H will be though one


        // A combination of a sign on % and two symbols from ranges 0-9 and A-F


        // (sexadecimal figures)


    $val=ereg_replace ('. * % ([0-9A-F] {2}). * ', '\1 ', $H);


        // We appropriate{give} $val result of replacement of expression,


        // Containing percent{interest} and two symbols from intervals marked above,


        // On these most two symbols


        // To put it briefly, now in $val at us next 2 symbols,


        // Before which in initial expression there was a percent{an interest}


    $newval=chr (hexdec ($val)); // it is received sivol with number{room},


        // Received perevedeniem received in $val


        // Sexadecimal number in "normal"


    $H=str_replace (' % '. $ val, $newval, $H);


        // Standard line function of replacement-


        // Replaces podstroku, consisting of percent{interest} and drukh symbols


        // From a variable $var on a symbol, which these two


        // Sexadecimal a symbol coded


} // the end of a cycle:)



Total:

$er_time=date (" H:i:s d M Y "); // it is written down current time at line,


    // Using the set format


$U=getenv ("HTTP_USER_AGENT"); // we obtain the data on a software,


    // Which ispol`uet the user


$H=getenv ("HTTP_REFERER"); // it is received URL from which there has come the visitor


$R=getenv ("REMOTE_ADDR"); // it is received IP the visitor


$W=getenv ("REQUEST_URI"); // the relative address of a page is received,


    // Which was requested by the visitor



while (ereg (' % ([0-9A-F] {2}) ', $H)) {// while in line $H will be though one


        // A combination of a sign on % and two symbols from ranges 0-9 and A-F


        // (sexadecimal figures)


    $val=ereg_replace ('. * % ([0-9A-F] {2}). * ', '\1 ', $H);


        // We appropriate{give} $val result of replacement of expression,


        // Containing percent{interest} and two symbols from intervals marked above,


        // On these most two symbols


        // To put it briefly, now in $val at us next 2 symbols,


        // Before which in initial expression there was a percent{an interest}


    $newval=chr (hexdec ($val)); // it is received sivol with number{room},


        // Received perevedeniem received in $val


        // Sexadecimal number in "normal"


    $H=str_replace (' % '. $ val, $newval, $H);


        // Standard line function of replacement-


        // Replaces podstroku, consisting of percent{interest} and drukh symbols


        // From a variable $var on a symbol, which these two


        // Sexadecimal a symbol coded


} // the end of a cycle:)



$f=fopen ("logs/visits.log", ' a '); // is farther - understandably, we write all this to a file


flock ($f, 2);


fwrite ($f, " $er_time\n Br: $U\n Rf: $H\n IP: $R\n Rq: $W\n ");


fclose ($f);



Already on broad gullies of this script it is possible to judge, whence there has come the visitor, on what pages he has passed and on what page has left{abandoned} a site. Yes, certainly, it was possible to make it and sessions - but to us laziness. And so - 2 minutes, also are possible to enjoy!:)

You learn{find out} her  from thousand


It - a basis. It is possible to think up much that further: for example, from the lines containing "http://www.yandex.ru/yandsearch" to cut out that part which, actually, contains search, and to write down in any file such as "yandex.log". In general, on what imaginations will suffice - all is possible zababakhat`!


Success!