Jump to content

online list


birbal

Recommended Posts

how can i check users are online or offline in my site. any one please give some idea on it

Link to comment
Share on other sites

when they log in, set a flag in their account. Then keep track of when they leave through sessions or when they logout. check the status of that flag when seeing if users are online or not.

Link to comment
Share on other sites

but there is a problem if user dont logout (i mean session does not unset) then how to check the user are online or not. so how can i do that automaticaly. i mean after a particular time user dont loads any page they will be cosidered as offline. and their session will be unset and cleared from database.

Link to comment
Share on other sites

their session won't be in the database. when a page need to clear itself out after a certain amount of inactivity, set the the flag for that user to off/false, etc.

Link to comment
Share on other sites

There's no need to shout. Have a look at this post: http://w3schools.invisionzone.com/index.ph...ost&p=96608.Edit: whoops, I actually meant to link to the thread JSG has in his post. That's what comes from not reading the posts correctly :).

Link to comment
Share on other sites

If you're trying to get a list of users who are currently "active", it's best to store a timestamp in your database that says the last time they loaded a page. You can look up the list of users who have loaded a page within the past few minutes to get the list of active users. You can also use a custom session handler to store your sessions in the database, there's a series of functions here that will store sessions in the database and give you an easy way to look up the number of people who were active recently:http://w3schools.invisionzone.com/index.php?showtopic=9731

Link to comment
Share on other sites

If you're trying to get a list of users who are currently "active", it's best to store a timestamp in your database that says the last time they loaded a page. You can look up the list of users who have loaded a page within the past few minutes to get the list of active users. You can also use a custom session handler to store your sessions in the database, there's a series of functions here that will store sessions in the database and give you an easy way to look up the number of people who were active recently:http://w3schools.invisionzone.com/index.php?showtopic=9731
ok i checked..that is what i was looking for. thank you!but there is some problem.....(1)
function custom_session_open($save_path, $session_name)

here what parameter will be passed in $save_path and $session_name?(2) whe i am using the custom_session_write(),custom_session_read(),custom_session_destroy() it is working and interacting with the database. but when i am putting these in the session_set_save_handler() it is not working with datbase. i cant find where is wrong.

Link to comment
Share on other sites

here what parameter will be passed in $save_path and $session_name?
PHP calls all of those functions automatically. This page lists all of the functions and the parameters that get sent to each one:http://php.net/manual/en/function.session-...ave-handler.phpI imagine that the save path is used for the session file handler, it's not necessary for a database though. If you want, you can use an error log to have those functions record the values they get sent if you want to take a look at them.
whe i am using the custom_session_write(),custom_session_read(),custom_session_destroy() it is working and interacting with the database. but when i am putting these in the session_set_save_handler() it is not working with datbase. i cant find where is wrong.
You shouldn't call those functions directly, PHP will handle that. You can add some code to make all errors go to an error log and then you can check that log to see if there's anything going wrong behind the scenes.
error_reporting(E_ALL);ini_set('error_log', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'error.log');ini_set('html_errors', 0);ini_set('log_errors', 1);ini_set('display_errors', 0);

That will redirect all errors to a file called error.log in the same directory as the script.

Link to comment
Share on other sites

PHP calls all of those functions automatically. This page lists all of the functions and the parameters that get sent to each one:http://php.net/manual/en/function.session-...ave-handler.phpI imagine that the save path is used for the session file handler, it's not necessary for a database though. If you want, you can use an error log to have those functions record the values they get sent if you want to take a look at them.You shouldn't call those functions directly, PHP will handle that. You can add some code to make all errors go to an error log and then you can check that log to see if there's anything going wrong behind the scenes.
error_reporting(E_ALL);ini_set('error_log', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'error.log');ini_set('html_errors', 0);ini_set('log_errors', 1);ini_set('display_errors', 0);

That will redirect all errors to a file called error.log in the same directory as the script.

Ok ...but still have some problem in session...handler()...it is not still working..i followed all things. ..but when i am setting a session(eg. $_SESSION['code']=123) it is not storing it in database..
Link to comment
Share on other sites

OK, did you read my last post? Are you sending errors to the log and checking it? Are you seeing any errors in the log?Did you set up the session database table correctly? The code I posted doesn't do any error checking with the database, so if you think there's a problem with the database then error checking can be added to that code so it will print the error from MySQL. That would only be a problem if the table was not set up correctly.

Link to comment
Share on other sites

OK, did you read my last post? Are you sending errors to the log and checking it? Are you seeing any errors in the log?Did you set up the session database table correctly? The code I posted doesn't do any error checking with the database, so if you think there's a problem with the database then error checking can be added to that code so it will print the error from MySQL. That would only be a problem if the table was not set up correctly.
1) table is ok as far i checked it and i had added mysql_error() with the all php_mysql function...they are not showing any thing.2) yes i checked it now writing down the error[30-Sep-2010 06:43:42] PHP Notice: A session had already been started - ignoring session_start() in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\session.php on line 83
Link to comment
Share on other sites

[30-Sep-2010 07:47:50] PHP Notice: Undefined variable: _session in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\sescheck1.php on line 9error showing thisno i cant use session variable to other page also.

Link to comment
Share on other sites

ohh my mistake..here is the both file..sescheck.php

<?phpinclude "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\session.php";echo "php starts";$_SESSION["testvar"]=13;echo "php end";?>

sescheck1.php

<?phpecho "starts";include "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\session.php";echo $_SESSION["testvar"];echo "ends";?>

it is showing the session now...but it is not storing the session in datbase ...when i use this ..it is not showing stored session

select * from session;

why?

Link to comment
Share on other sites

If everything is set up correctly then it will store the sessions in the database. You should be able to use a tool like phpMyAdmin to look at all of the records in that table. See if you can use the get_user_count function to return the number of users online, it should return 1.

Link to comment
Share on other sites

<?phpinclude "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\phpfunction.php";error_reporting(E_ALL);ini_set('error_log','C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\error.log');ini_set('html_errors', 0);ini_set('log_errors', 1);ini_set('display_errors', 0);$cOndb=connect_db("dtabase");//============================================================================================================//open session//============================================================================================================function custom_session_open($save_path,$session_name){return(true);}//============================================================================================================////close session//============================================================================================================function custom_session_close(){return custom_session_gc(get_cfg_var("session.gc_maxlifetime"));}//============================================================================================================//session read //============================================================================================================function custom_session_read($id){$output="";$qry=<<<ENDselect * from session where(id="$id")END;$res=query($qry);$row=q_out($ses_path,$ses_name);if($row)	{	$output=$row;	}else	{	$output="";	}return $output;}//============================================================================================================//session write //============================================================================================================function custom_session_write($id,$ses_data){$curtime=time();$qry=<<<ENDinsert into session values("$id","$ses_data","$curtime") on duplicate key update id="$id",content="$ses_data",timestamp="$curtime"END;$res=query($qry);return(true);}//============================================================================================================//session destroy//============================================================================================================function custom_session_destroy($id){$qry=<<<ENDdelete from session where(id="$id")END;$res=query($qry);return(true);}//============================================================================================================//session garbage collection time in seconds//============================================================================================================function custom_session_gc($maxtime){$cur=time();$exp=$cur-$maxtime;$qry=<<<ENDdelete from session where(timestamp<$exp)END;return(true);}//============================================================================================================//============================================================================================================session_set_save_handler('custom_session_open','custom_session_close','custom_session_read','custom_session_write','custom_session_destroy','custom_session_gc');echo "session function is ok";?>

this the code..quey(),q_out(),db_connect()..is customized function described in phpfunction.php(included)i dont have phpmyadmin...using mysql command prompt.pleas correct me..where i am wrong.

Link to comment
Share on other sites

and i mysql command promt returning empty set in session table. (mysql table where i storing session)

id varchar(40)primary keycontent texttimestamp int not null

this is the datastructrue of my table session

Link to comment
Share on other sites

it is working now. :)thanks a lot justsomeguy and all.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...