who's online
Moderator: General Moderators
who's online
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']
$_SERVER['PHP_AUTH_USER']
logscript
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; }}
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Code: Select all
<?php
$fp2=fopen("data.lock",'r');
flock ($fp2,2);
...
Counter code.
...
flock ($fp2,3);
?>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..
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..
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You could use basename()
Mac
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"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?
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?