FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


User conection and disconectios





D'Artagnan
Hi,

i'm searching a way to log user conections (openings) and disconections(closeing) of a page.

Its simple a need something that tell me when someone load a page and when this one close that page...
MrBlueSky
To log when users load a page you can put something like this at the top of every PHP page:

Code:

<?php

    @$str = "IP: ".$_SERVER["REMOTE_ADDR"]."\n";
    @$str .= "USERAGENT: ".$_SERVER["HTTP_USER_AGENT"]."\n";
    @$str .= "REQUEST: ".$_SERVER["REQUEST_URI"]."\n";
    @$str .= "REFERRER: ".$_SERVER["HTTP_REFERER"]."\n";
    @$str .= "DATE: ".date('l dS \of F Y h:i:s A')."\n\n\n";
    $h = @fopen("log/access.log", "w");
    @fwrite($h, $str);
    @fclose($h);

?>


It is not possible to know when someone closes a page. At least not without some complicated javascript solution.
D'Artagnan
Thank you ^^

Quote:

It is not possible to know when someone closes a page. At least not without some complicated javascript solution.


i was afraid of it...
DjinniFire
D'Artagnan wrote:
Thank you ^^

Quote:

It is not possible to know when someone closes a page. At least not without some complicated javascript solution.


i was afraid of it...


I can't find it but there probably is a simple javascript code that pops up when a user closes the page so I mean if you can find that, I bet you can do something to quickly submit that a user closed the page within the javascript :/ not sure

I know a lot of those social websites have people putting the script that goes BYEEEEEEEEEEe when you exit the page -.- it's really annoying
jabapyth
the javascript is
Code:

function sendRequest(url,callback,postData) {
   var req = createXMLHTTPObject();
   if (!req) return;
   var method = (postData) ? "POST" : "GET";
   req.open(method,url,true);
   req.setRequestHeader('User-Agent','XMLHTTP/1.0');
   if (postData)
      req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
   req.onreadystatechange = function () {
      if (req.readyState != 4) return;
      if (req.status != 200 && req.status != 304) {
//         alert('HTTP error ' + req.status);
         return;
      }
      callback(req);
   }
   if (req.readyState == 4) return;
   req.send(postData);
}

function XMLHttpFactories() {
   return [
      function () {return new XMLHttpRequest()},
      function () {return new ActiveXObject("Msxml2.XMLHTTP")},
      function () {return new ActiveXObject("Msxml3.XMLHTTP")},
      function () {return new ActiveXObject("Microsoft.XMLHTTP")}
   ];
}

function createXMLHTTPObject() {
   var xmlhttp = false;
   var factories = XMLHttpFactories();
   for (var i=0;i<factories.length;i++) {
      try {
         xmlhttp = factories[i]();
      }
      catch (e) {
         continue;
      }
      break;
   }
   return xmlhttp;
}
//// all that is just for ajax handling, gotten from quirksmode.com

window.onunload =function (){
    sendRequest("/logquit.php",function(){});
}
Related topics
Point to the user online
350 x 20 User Bar + Tutorial
Dynamic User Customizable Sites. CSS + PHP = Awesome!
User Membership Script Needed....In Trouble really need 1 !
Explorer XP help
How did you come up with your username?
Javascript to create non-Sidebar bookmark in Firefox?
Give each user a sub directory?
A user/profile management system
Follow the user
How hard is it to make a user database.
How to Block shared network drive accesss for Limited User??
User Authentication
Create Usernames: User Account to DB vs. TABLES vs. CELL
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.