Re: [PHP] List of sessions

2006-05-06 Thread Richard Lynch
On Thu, May 4, 2006 10:56 pm, Tony Aldrich wrote:

 Honestly, the easiest way to solve this is to switch to 'user' PHP
 sessions:
 http://php.net/session-set-save-handler


 Thanks. I'm trying now to do this.
 I'm wondering about session-set-save-handler - what is manual
 garbage
 collector here?
 It means I must explicitly unset all variables or something else I
 must
 do?

You'd want to delete any records from your database that are stale

This is the important part of what you were asking about in the first
place.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] List of sessions

2006-05-06 Thread tedd

Hi:

While we're on the subject of listing sessions, what does the 
following code do?


session_start();

$path = ini_get('session.save_path');
$handle = dir($path);

while ($filename = $handle-read())
{
  if (substr($filename, 0, 5) == 'sess_')
  {
$data = file_get_contents($path/$filename);

if (!empty($data))
{
  session_decode($data);
  $session = $_SESSION;
  $_SESSION = array();
  echo(pre);
  echo Session [ . 
substr($filename, 5) . ]\n;

  print_r($session);
  echo \n--\n\n;
  echo(/pre);
}
  }
}

It looks dangerous.

tedd
--

http://sperling.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] List of sessions

2006-05-06 Thread chris smith

On 5/7/06, tedd [EMAIL PROTECTED] wrote:

Hi:

While we're on the subject of listing sessions, what does the
following code do?

session_start();

$path = ini_get('session.save_path');
$handle = dir($path);

while ($filename = $handle-read())
{
  if (substr($filename, 0, 5) == 'sess_')
  {
$data = file_get_contents($path/$filename);

if (!empty($data))
{
  session_decode($data);
  $session = $_SESSION;
  $_SESSION = array();
  echo(pre);
  echo Session [ .
substr($filename, 5) . ]\n;
  print_r($session);
  echo \n--\n\n;
  echo(/pre);
}
  }
}


Goes through 'session.save_path' and looks for session files. If it
finds one, it opens it and prints it out.

Could be quit dangerous on a shared host, yes.

--
Postgresql  php tutorials
http://www.designmagick.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] List of sessions

2006-05-06 Thread Richard Lynch
On Sat, May 6, 2006 9:42 am, tedd wrote:
 While we're on the subject of listing sessions, what does the
 following code do?

Looks like it snoops through all the sessions it can find.

I suspect it will also NUKE the last session, where 'last' is whatever
order readdir() feels like returning, which is not defined as any
particular order...

At least, I assume that after setting $_SESSION to array() that last
time and ending, it's going to have nuked the last session...

It might actually nuke them all for that matter...

If session_decode() switches the ID around as well, then its gonna
nuke them all, no?

Maybe it's just a re-boot nuke all old sessions script...

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] List of sessions

2006-05-04 Thread Joe Wollard

If you store your sessions in a database then your could gain a little mode
control over your session, but I think what you're asking is if there's a
way to tell if a user has closed the browser thus killing the session on
their side. If that's what you're asking then the answer is not going to lie
strictly with PHP as the server has no way to ping a user's browser. A quick
hack off the top of my head might be to find a creative way of using the
onBeforePageUnload() (or w/e it is) javascript function along with frames.

Anyway, you can check out php.net for more details on how to use a database
for session storage:
http://www.php.net/manual/en/function.session-set-save-handler.php

Cheers,
- Joe


On 5/4/06, Tony Aldrich [EMAIL PROTECTED] wrote:


Well, I mean visitors of site. They can open it in several windows or in
several browsers. I understand that each browser on a machine will be a
session (in simple explanation). And for all of them I create some info in
database. Then they close browser. I must clean up unused info.
That's why I want to query alive sessions. Or query their death time
(timeout).
I thought of something like

$sess=get_session_list();

or

$isalive=is_session_alive($session_id);

Thanks.



On 5/4/06, Gerry D [EMAIL PROTECTED] wrote:

 Can you have more than 1 session?

 On 5/2/06, Tony Aldrich [EMAIL PROTECTED] wrote:
  Good day,
  Does anybody know how to get a list of current sessions?
  I need to clear some database rows that where associated with some
SID.
  Can it be done without probing of maxlifetime?





Re: [PHP] List of sessions

2006-05-04 Thread Tony Aldrich

Thanks all for explanations.
I'll try to use callback functions.

Tony.

On 5/4/06, Joe Wollard [EMAIL PROTECTED] wrote:


If you store your sessions in a database then your could gain a little
mode control over your session, but I think what you're asking is if there's
a way to tell if a user has closed the browser thus killing the session on
their side. If that's what you're asking then the answer is not going to lie
strictly with PHP as the server has no way to ping a user's browser. A quick
hack off the top of my head might be to find a creative way of using the
onBeforePageUnload() (or w/e it is) javascript function along with frames.

Anyway, you can check out php.net for more details on how to use a
database for session storage: 
http://www.php.net/manual/en/function.session-set-save-handler.php


Cheers,
- Joe



On 5/4/06, Tony Aldrich [EMAIL PROTECTED] wrote:

 Well, I mean visitors of site. They can open it in several windows or in
 several browsers. I understand that each browser on a machine will be a
 session (in simple explanation). And for all of them I create some info
 in
 database. Then they close browser. I must clean up unused info.
 That's why I want to query alive sessions. Or query their death time
 (timeout).
 I thought of something like

 $sess=get_session_list();

 or

 $isalive=is_session_alive($session_id);

 Thanks.



 On 5/4/06, Gerry D [EMAIL PROTECTED] wrote:
 
  Can you have more than 1 session?
 
  On 5/2/06, Tony Aldrich [EMAIL PROTECTED] wrote:
   Good day,
   Does anybody know how to get a list of current sessions?
   I need to clear some database rows that where associated with some
 SID.
   Can it be done without probing of maxlifetime?
 





Re: [PHP] List of sessions

2006-05-04 Thread Richard Lynch
On Wed, May 3, 2006 11:29 pm, Tony Aldrich wrote:
 Well, I mean visitors of site. They can open it in several windows or
 in
 several browsers. I understand that each browser on a machine will be
 a
 session (in simple explanation). And for all of them I create some
 info in
 database. Then they close browser. I must clean up unused info.
 That's why I want to query alive sessions. Or query their death time
 (timeout).
 I thought of something like

 $sess=get_session_list();

 or

 $isalive=is_session_alive($session_id);

Honestly, the easiest way to solve this is to switch to 'user' PHP
sessions:
http://php.net/session-set-save-handler

Once you do that, you're already nuking the actual session data for
expired sessions in your database, and you can delete anything else in
parallel.

Your only other option would be to troll through /tmp looking for PHP
session filenames that match the session ID or whatever, and then
searching your database for IDs that aren't listed in there, and...

You'd probably end up with a race condition sooner or later, and this
would be dog-slow if you have lots of visitors, and you really don't
want to do it this way.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] List of sessions

2006-05-04 Thread Tony Aldrich


Honestly, the easiest way to solve this is to switch to 'user' PHP
sessions:
http://php.net/session-set-save-handler



Thanks. I'm trying now to do this.
I'm wondering about session-set-save-handler - what is manual garbage
collector here?
It means I must explicitly unset all variables or something else I must
do?



Once you do that, you're already nuking the actual session data for

expired sessions in your database, and you can delete anything else in
parallel.

Your only other option would be to troll through /tmp looking for PHP
session filenames that match the session ID or whatever, and then
searching your database for IDs that aren't listed in there, and...



Yes, I've tried this already - as a quick solve.
I found out that session_save_path() returns null ander Windows (where I'm
testing) and real folder on host side.
And this means that I must use Windows temp folder and don't forget to
filter files as 'sess_*'.

Tony.


Re: [PHP] List of sessions

2006-05-03 Thread Tony Aldrich

Well, I mean visitors of site. They can open it in several windows or in
several browsers. I understand that each browser on a machine will be a
session (in simple explanation). And for all of them I create some info in
database. Then they close browser. I must clean up unused info.
That's why I want to query alive sessions. Or query their death time
(timeout).
I thought of something like

$sess=get_session_list();

or

$isalive=is_session_alive($session_id);

Thanks.



On 5/4/06, Gerry D [EMAIL PROTECTED] wrote:


Can you have more than 1 session?

On 5/2/06, Tony Aldrich [EMAIL PROTECTED] wrote:
 Good day,
 Does anybody know how to get a list of current sessions?
 I need to clear some database rows that where associated with some SID.
 Can it be done without probing of maxlifetime?



[PHP] List of sessions

2006-05-02 Thread Tony Aldrich

Good day,
Does anybody know how to get a list of current sessions?
I need to clear some database rows that where associated with some SID.
Can it be done without probing of maxlifetime?

Thanks in advance.
Tony.