Page 1 of 1
who's online
Posted: Wed Nov 20, 2002 6:38 am
by Cyphonic
how can i make a script that displays the username of the users online? I'm using .htaccess, so the username variable is:
$_SERVER['PHP_AUTH_USER']
logscript
Posted: Wed Nov 20, 2002 7:29 am
by bumpy
Code: Select all
<?php
session_start();
if(!session_is_registered('counted')){
$agent = $_SERVERї'HTTP_USER_AGENT'];
$uri = $_SERVERї'REQUEST_URI'];
$user = $_SERVERї'PHP_AUTH_USER'];
$ip = $_SERVERї'REMOTE_ADDR'];
$ref = $_SERVERї'HTTP_REFERER'];
$dtime = date('r');
if($ref == ""){
$ref = "None";
}
if($user == ""){
$user = "None";
}
$entry_line = "$dtime - IP: $ip | Agent: $agent | URL: $uri | Referrer: $ref | Username: $user \n";
$fp = fopen("logs.txt", "a");
fputs($fp, $entry_line);
fclose($fp);
session_register('counted');
}
?>
This is maybe a bit more than you need, but as you can see you just start a session when you log in, and as long as you are logged in (=session_is_registered) you show up in the log.
In order to display all users online you just could open logs.txt and readthrough,
Code: Select all
<? for($x=0;$x<count($fp);$x++){ if($user != "none" ) {echo $user; }}
?>
But this way, even offline users are displayed, so you should add an if-statement that requires a maximum time difference between actual time and the logged time
Posted: Wed Nov 20, 2002 1:25 pm
by Cyphonic
Well, how can i do that, then?
Posted: Thu Nov 21, 2002 2:03 am
by twigletmac
You've been given quite a lot of code - have you attempted to implement any of it?
Mac
Posted: Thu Nov 21, 2002 6:27 am
by qads
lol

, take it easy twigle, he only asked cos he does't know..maybe he does and does't wanna try it out? but who knows?

Posted: Thu Nov 21, 2002 6:31 am
by twigletmac
Sorry, I sounded a bit harsher than I intended to. I was really just looking for a bit more information just in case I had to run out my 'we-are-not-a-script-writing-service' bit.
Mac
Posted: Thu Nov 21, 2002 5:34 pm
by HiDDeN
Code: Select all
<?php
$fp2=fopen("data.lock",'r');
flock ($fp2,2);
...
Counter code.
...
flock ($fp2,3);
?>
To make it safe for heavy-loaded sites it should be wrapped with locked protection. I had a problem, my counter has been resetting because multiple users were writing to the file at the same time.
Posted: Fri Nov 22, 2002 7:00 am
by Cyphonic
OK. Thanks a lot for your help. I've sorted it out now.. But does anyone know how to read a filname, without reading the extension??
Say I want to display all the filenames of the files in a directory, but only the filename, not the extension!
Like:
"index.php" becomes "index"
"scripts.php" becomes "script"
Anyone knows how to do that? Please let me know..
Posted: Fri Nov 22, 2002 7:08 am
by twigletmac
You could use
basename()
Code: Select all
/* Examples from the manual */
$path = "/home/httpd/html/index.php";
$file = basename ($path); // $file is set to "index.php"
$file = basename ($path,".php"); // $file is set to "index"
Mac
Posted: Fri Nov 22, 2002 5:17 pm
by Cyphonic
Great!! Just what I had in mind!!
So.. another question then; (I really appreciate the help i'm getting here guys.. thanks A LOT!)
I want to list the filenames in a directory ( i'm actually talking about images). Now i want, for each image/file, a text field where I can type in a new filename, press submit and the files are renamed. I know how to do the rename thing, but getting a separate textfield for each file, is what I want you guys to explain me how to do..
Thanks, in advance..
Edit: Am I totally off-piste if say that I think it has something to do with the "for" thingy?