ajax-live-users

Gesponsorde koppelingen

PHP script bestanden

  1. ajax-live-users

« Lees de omschrijving en reacties

[show.php]

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php

function showusers() {
include("config.php");
$num = mysql_num_rows($res);

if (!($res = mysql_query ($sql))) {
  trigger_error (mysql_error ());
}

else {
    if($num >= 1) {
        $i = 0;
        while($data = mysql_fetch_assoc($res)) {
            if($i > 0) {
                $userdata .= ", " . $data[$namefield];
    
            }
else {
                $userdata = $data[$namefield];
            }

            $i++;
        }
                
    }
else {
        $userdata = "Er zijn geen users online";
    }
}

?>

<script type="text/javascript" src="ajax.js"></script>

<div onmouseOver="ajaxFunction();" id="usercontainer">
<?php
echo $userdata;
?>

</div>
<?php
}
?>


[users.php]
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
//return online-users to ajax
include("config.php");
$num = mysql_num_rows($res);
if (!($res = mysql_query ($sql))) {
  trigger_error (mysql_error ());
}

else {
    if($num >= 1) {
        $i = 0;
        while($data = mysql_fetch_assoc($res)) {
            if($i > 0) {
                $userdata .= ", " . $data[$namefield];
    
            }
else {
                $userdata = $data[$namefield];
            }

            $i++;
        }
                
    }
else {
        $userdata = "Er zijn geen users online";
    }
}

echo $userdata;

?>


[ajax.js]
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function ajaxFunction()
  {
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
        document.getElementById('usercontainer').innerHTML = xmlHttp.responseText;
        }
      }
    xmlHttp.open("GET","users.php",true);
    xmlHttp.send(null);
  }


[config.php]
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php

$dbHost
                        = "";
$dbUser                     = "";
$dbPass                        = "";
$dbName                        = "";
$namefield                    = "";

mysql_connect($dbHost, $dbUser, $dbPass) or trigger_error(mysql_error());
mysql_select_db($dbName) or trigger_error(mysql_error());

$qry = "SELECT * FROM users WHERE status = 'online'";

?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.