WN

WN (https://www.wn.se/forum/index.php)
-   Serversidans teknologier (https://www.wn.se/forum/forumdisplay.php?f=4)
-   -   Visa antal online i på PHP sidor (https://www.wn.se/forum/showthread.php?t=9637)

Davve 2005-09-02 01:27

Tidigare använde jag mig av ASP på mina sidor och då vart det inga problem.. Nu vill jag visa antal ONLINE på PHP sidor, nån som vet hur man gör det enklast?

koala 2005-09-02 03:10

Jag gjorde en liknande grej, och då definierade jag en användare som online om han/hon uppdaterat sin session de senaste x sekunderna. 300 fungerar ganska bra (5 minuter).

Davve 2005-09-02 14:56

Nån som kan dela med sig av det scriptet?

b_andersson 2005-09-02 15:05

Det finns mängder av gratis script som gör det, här är ett av dom som dök upp vid en sökning på google:

CJ Users Online V1.0

//Björn

Davve 2005-09-05 09:02

Jag har hittat masso med sådana script men alla med db, finns det inget utan DB som kan vissa den informationen på PHP sidor?

Menion 2005-09-08 12:34

Citat:

Originally posted by Davve@Sep 5 2005, 09:02
Jag har hittat masso med sådana script men alla med db, finns det inget utan DB som kan vissa den informationen på PHP sidor?

Jo, du kan alltid köra med sessions i filer, och sen räkna antalet filer för att komma underfund med hur många som är online ;)

koala 2005-09-08 13:30

Citat:

Ursprungligen postat av Menion
Citat:

Ursprungligen postat av Davve
Jag har hittat masso med sådana script men alla med db, finns det inget utan DB som kan vissa den informationen på PHP sidor?

Jo, du kan alltid köra med sessions i filer, och sen räkna antalet filer för att komma underfund med hur många som är online

Dock får man se upp så man inte råkar räkna alla sessioner på servern, om det är en gemensam mapp för sessionerna, och servern hostar flera sidor. (Inte den säkraste lösningen att göra så heller för den delen.)

Jim_Westergren 2005-09-08 19:45

Detta skript använder inga sessioner utan skriver IPna i en logg fil som den sedan tar bort efter en definierad tid.

Citat:

+----------------------------------------+
| UserOnline 2.1 |
| |
| Documentation for the installation |
| of UserOnline 2.1 |
| |
+----------------------------------------+


In order to setup the UserOnline Script, you must do the following:

1. unpack ZIP
2. Edit config.php3
3. Upload all files
4. Insert the UserOnline code into the pages, that the current
number of users should be shown

+----------------------------------------+
After you've unpacked the zip, you have to edit the variables in the config.php3.

<?php

// Timeout - After this time the users will
// be deleted (in minutes)
$timer = 100;

// Name of the file where all the data, about
// the user's activity will be saved
$filename = "$DOCUMENT_ROOT/useronline/log.txt";

?>

+----------------------------------------+
There are two possibilities to setup the UserOnline script on your homepage:

A. HTML: [img]your/path/to/useronline.php4[/img]
If you chose the HTML version, the current number of users won't be shown,
but the user will be logged.

B. PHP: <?php include("your/path/to/useronline.php4"); ?>
Please consider that when you insert the PHP code, the current amount of
users online will be outputted.
The pages that you insert this code into have to be PHP 4 compatible


+----------------------------------------+
If you encounter any bugs while using this
script, then please write those into our
forum:http://scripts.w3secrets.com/forum/


Här kommer config.php3:


Citat:

<?php

// Timeout - After this time the users will
// be deleted (in minutes)
$timer = 100;



// Name of the file where all the data, about
// the user's activity will be saved
$filename = "$DOCUMENT_ROOT/useronline/log.txt";

?>

Här kommer useronline.php4:

Citat:

<?php
################################################## ######################
# Copyright © 2001 Wanja Hemmerich #
# First version published April 2001 - This version November 2001 #
################################################## ######################
# COPYRIGHT NOTICE #
# Copyright 2001 Wanja Hemmerich. All rights reserved. #
# #
# This program may be used and modified, as long as this copyright #
# notice stays intact. #
# #
# Wanja Hemmerich is not responsible for damage, which is possibly #
# caused by his program. #
# #
# This program code may not be sold, nor auctioneered, nor be used in #
# any other commercial way in order to make money. #
# #
# This Programm may not be distributed to download neither by #
# Internet, nor by another medium. #
################################################## ######################
# By using this programm, you agree with these conditions. #
# #
################################################## ######################
# The text above must be kept intact under all circumstances. #
################################################## ######################


include ("./config.php3");

if (!$datei) $datei = dirname(__FILE__)."/$filename";
$time = @time();
$ip = $REMOTE_ADDR;
$string = "$ip|$time\n";
$a = fopen("$filename", "a+");
fputs($a, $string);
fclose($a);

$timeout = time()-(60*$timer);

$all = "";
$i = 0;
$datei = file($filename);
for ($num = 0; $num < count($datei); $num++) {
$pieces = explode("|",$datei[$num]);

if ($pieces[1] > $timeout) {
$all .= $pieces[0];
$all .= ",";
}
$i++;
}

$all = substr($all,0,strlen($all)-1);
$arraypieces = explode(",",$all);
$useronline = count(array_flip(array_flip($arraypieces)));

// display how many people where activ within $timeout
echo $useronline;

// Delete
$dell = "";
for ($numm = 0; $numm < count($datei); $numm++) {
$tiles = explode("|",$datei[$numm]);
if ($tiles[1] > $timeout) {
$dell .= "$tiles[0]|$tiles[1]";
}
}

if (!$datei) $datei = dirname(__FILE__)."/$filename";
$time = @time();
$ip = $REMOTE_ADDR;
$string = "$dell";
$a = fopen("$filename", "w+");
fputs($a, $string);
fclose($a);
?>


Gör en tom fil som heter log.txt och sedan kan du bara ha <?php include("your/path/to/useronline.php4"); ?> för att skriva nummret. Jag använder det och det funkar bra.


Alla tider är GMT +2. Klockan är nu 16:52.

Programvara från: vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Svensk översättning av: Anders Pettersson