whoisonline script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
doggy
Forum Commoner
Posts: 80
Joined: Tue Dec 09, 2003 5:01 am
Location: South Africa

whoisonline script

Post by doggy »

Code: Select all

function online() {
    global $admin, $user, $cookie, $prefix, $db;
    cookiedecode($user);
	$ip = $_SERVER["REMOTE_ADDR"];
    $uname = $cookie[1];
    if (!isset($uname)) {
        $uname = "$ip";
        $guest = 1;
    }
	if (is_admin($admin)) {
		$admin = base64_decode($admin);
// this line is giving me problims //
	    $admin = explode(":", $admin);
// end problim //
        $uname  = "$admin[0]";
        $guest = 2;
    }
    $past =time()-600;
    $sql = "DELETE FROM ".$prefix."_session WHERE time < $past";
    $db->sql_query($sql);
    $sql = "SELECT time FROM ".$prefix."_session WHERE uname='$uname'";
    $result = $db->sql_query($sql);
    $ctime = time();
    if ($row = $db->sql_fetchrow($result)) {
	$sql = "UPDATE ".$prefix."_session SET uname='$uname', time='$ctime', host_addr='$ip', guest='$guest' WHERE uname='$uname'";
	$db->sql_query($sql);
  	} else {
	$sql = "INSERT INTO ".$prefix."_session (uname, time, host_addr, guest) VALUES ('$uname', '$ctime', '$ip', '$guest')";
	$db->sql_query($sql);
	}
}
Warning: base64_decode() expects parameter 1 to be string, array given in C:\FoxServ\www\atlas-php\mainfile.php on line 414

i have no idea what is going on ... please help
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

What do you get if you do:

Code: Select all

var_dump($admin);
Mac
User avatar
doggy
Forum Commoner
Posts: 80
Joined: Tue Dec 09, 2003 5:01 am
Location: South Africa

Post by doggy »

array(1) { [0]=> string(0) "" }
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

There's the problem then, $admin is an array not a string. This will cause you problems with the explode() function too. What were you expecting to be in $admin?

Mac
User avatar
doggy
Forum Commoner
Posts: 80
Joined: Tue Dec 09, 2003 5:01 am
Location: South Africa

Post by doggy »

i have installed phpnuke and i making it now for a company so i wanne make the whois online that people can see how many administrators are online and what administrators are online ( nicknames ) so that is why i need to explode the $admin thingy to see what is the administrators nickname ,,,, but i am not that good with php so thats why i really need help ,,,
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

i dont know if you have thought of doing it this way but here goes

<--user3 logs in
<--a value is set in there myswl row (update record)or set a flag
<--user3 exits
<-- a value is changed back again (or changed back at set interval to ensure the person hasnt just exited without clicking logout

on the CMS

<-- run a query checking values in a database equivalent to the va;lue you decide to create when someone has logged in
<-- run mysql_affected_rows() to see how many people are logged in currently

i dont know whether this is the way forums do it, but this is the way i envision it to be
User avatar
doggy
Forum Commoner
Posts: 80
Joined: Tue Dec 09, 2003 5:01 am
Location: South Africa

Post by doggy »

amm dude sounds cool but i don`t really know or anderstand what you are saying. could you maybe reword. i am not that good of a web developer and i don`t know so much about php scripting.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

ok

i will try and explain it, as thoroughly as i can

- user1 goes into the login area and successfully logs in
- a session is created using

Code: Select all

$_SESSION[username] = $_POST[username] 
//i think thats right, im tired!
insert data into the database so that you can check for it later

Code: Select all

"INSERT logged_in INTO users_status WHERE username = '$_SESSION[username]'"
in the CMS section
to see how many people have there status set as logged_in use........

Code: Select all

mysql_query = "SELECT * FROM mytable WHERE users_status = 'logged_in'";
print mysql_affected_rows();
this should give you a value of how many people matching that description so you do what you want to do

hope that helps
Post Reply