利用Jquery框架,Ajax调用当前在线用户
function UpdateOnline(){
- if (arguments[0]==true){
- $.ajax({
- url:'ajax.php?do=updateonline',
- type:'GET',
- success:function(){
- $('#updateonline').html(arguments[0])
- }
- }
- );
- }else{
- $.ajax({url:'ajax.php?do=updateonline',type:'GET'});
- }
- }
这个updateonline是div的ID。还有就是调用这个函数!
- $(document).ready(function(){
- UpdateOnline(true);
- window.setInterval("UpdateOnline(true)",60000);
- });
下面是服务端处理代码:
- $Now=time();
- $FileName='online.xml';
- $XML=new DomDocument;
- $XML->load($FileName);
- $Items=$XML->getElementsByTagName("item");
- $I=0;
- $AddXML=true;
- foreach ($Items as $Item){
- $IP=$Item->childNodes->item(0)->nodeValue;
- $Time=$Item->childNodes->item(1)->nodeValue;
- if($IP==GetIP()){
- $AddXML=false;
- }
- if($IP==@$_SESSION['IP']){
- $XML_Online=$XML->getElementsByTagName("online")->item(0);
- $XML_Online_Item_Select=$XML->getElementsByTagName("item")->item($I);
- $XML_Online_Item=$XML->createElement("item");
- $NewIP=$XML->createElement("ip",$IP);
- $XML_Online_Item->appendChild($NewIP);
- $NewTime=$XML->createElement("time",$Now);
- $XML_Online_Item->appendChild($NewTime);
- $XML_Online->replaceChild($XML_Online_Item,$XML_Online_Item_Select);
- $XML->save($FileName);
- }
- if(round(($Now-$Time)/60)>1){
- $Item=$XML->documentElement->getElementsByTagName("item")->item($I);
- $XML->documentElement->removeChild($Item);
- $XML->save($FileName);
- }
- $I++;
- }
- if($AddXML){
- $XML->formatOutput = true;
- $XML_Online=$XML->getElementsByTagName("online")->item(0);
- $XML_Online_Item=$XML->createElement("item");
- $XML_Online_Item_IP=$XML->createElement("ip",GetIP());
- $XML_Online_Item->appendChild($XML_Online_Item_IP);
- $XML_Online_Item_Time=$XML->createElement("time",$Now);
- $XML_Online_Item->appendChild($XML_Online_Item_Time);
- $XML_Online->appendChild($XML_Online_Item);
- $XML->save($FileName);
- $_SESSION['IP']=GetIP();
- }
- if($Items->length==0){
- echo'1';
- }else{
- echo $Items->length;
- }
- unset($Now,$FileName,$XML,$Items,$I,$AddXML);
配合了session来存储IP地址以区分用户。
下面是XML文件
-
127.0.0.1

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download
The most popular open source editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version
Visual web development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment
