Reply to Re: [PHP] trying to figure out the best/efficient way to tell who is logged into a site..

Your name:

Reply:


Posted by "Gustav Wiberg" on 09/14/05 00:49

----- Original Message -----
From: "Jason Barnett" <juzamjedi@gmail.com>
Cc: <php-general@lists.php.net>
Sent: Tuesday, September 13, 2005 11:25 PM
Subject: Re: [PHP] trying to figure out the best/efficient way to tell who
is logged into a site..


Close: You mix both of these ideas.

Create a custom session handler. This handler creates user entries in a
database. Then when you want to know how many are online you do a count on
the number of user entries in the table. Play around with different
gc_probability values to tune the efficiency.



On 9/13/05, bruce <bedouglas@earthlink.net> wrote:
>
> hi...
>
> anybody have pointers to trying to tell who/how long someone is logged
> into
> a system/site. i've thought about setting a session var, but i'm not sure
> how to read/tabulate this var across the entire group of people who'd be
> logged in. i've also thought about keeping track in a db tbl.. however,
> i'm
> still not sure that i've got a good way of tracking who's logged in, and
> still on...
>
> a possible approach would be to have the app periodically update the
> system
> whenever a logged in user goes from page to page...
>
> so, any thoughts/ideas/etc...
>
> -thanks
>
> bruce
> bedouglas@earthlink.net
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



--------------------------------------------------------------------------------


No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.10.23/99 - Release Date: 2005-09-12

Hi there!

Giving you a bit code... It might come in handy... :-)
I don't have time to explain it, but it may be good for experimenting...

All you guys, please comment if the code is well or bad written and why...
:-)



<?php

function chkIfPasswordTrue($un, $pw, $typeUser) {

//Make username and password in-casesensitive
//
$un = strtolower($un);

$pw = strtolower($pw);

$typeUser = strtolower($typeUser);

require("phpfunctions/opendb.php");



//Get ID for user based on username and password from database

//

$sql = "";

$sql = $sql . "SELECT IDAnvandare FROM tbanvandare WHERE";

$sql = $sql . " Anvandarnamn=" . safeQuote($un) . " AND";

$sql = $sql . " Losenord=" . safeQuote($pw) . " AND";

if ($typeUser == "customer") {

$sql = $sql . " Kund='Y'";

}
else if ($typeUser == "reseller") {

$sql = $sql . " Af='Y'";

}
else {

$sql = $sql . " Kund='Y'";

}

//echo "SQL = $sql";

$querys = mysql_query($sql);

$toarray = mysql_fetch_array($querys);



$id = $toarray["IDAnvandare"];

if ($id == Null or strlen($id)==0) {$id = 0;}



mysql_close();



//Return id for user, zero if incorrect login

//

return $id;

}





function getusername() {



//Get username from form if form have sent anything

//if there is an active usernamesession, then use session-variable

//to identifiy user

//

$un = "";



if (isset($_REQUEST["frmUsername"])) {

$un = $_REQUEST["frmUsername"];

}



if (isset($_SESSION["unBuy"])) {

$un = $_SESSION["unBuy"];

}



return $un;



}



function getpassword() {

//Get password from form if form have sent anything

//if there is an active passwordsession, then use session-variable

//to identifiy user

//

$pw = "";



if (isset($_REQUEST["frmPassword"])) {

$pw = $_REQUEST["frmPassword"];

}



if (isset($_SESSION["pwBuy"])) {

$pw = $_SESSION["pwBuy"];

}



return $pw;



}



function setsessions($username, $password, $typeUser) {

$userid = 0;
$username = trim($username);
$password = trim($password);
$typeUser = trim($typeUser);

if (strlen($username)>0 AND strlen($password)>0 AND strlen($typeUser)>0) {

$userid = chkIfPasswordTrue($username, $password, $typeUser);

}



//Set session-variable for user-identification

//

if ($userid>0) {

$_SESSION["unBuy"] = $username;
$_SESSION["pwBuy"] = $password;
$_SESSION{"typeUser"} = $typeUser;

}



return $userid;



}



?>



/G
http://www.varupiraten.se/

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация