session length

This is a discussion on session length within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi, Is there a possibility to find out how long a session is active? I mean i can easily say ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-14-2007
Ron Eggler
 
Posts: n/a
Default session length

Hi,

Is there a possibility to find out how long a session is active?
I mean i can easily say how long it's active by saving a in time when it's
started and a out time when the person clicks on a "logout" link for
example, but what's with the ones that just close the window? How can i
check how long a session was active?

Thanks, for help and recommodations!

Ron
Reply With Quote
  #2 (permalink)  
Old 12-15-2007
macca
 
Posts: n/a
Default Re: session length

Theres probably an easier way but couldn't you create an object that
writes to a log the start time of the session (thus creation of the
object) and then have a destructor that will write to the log the time
when the session (thus object) is destroyed?

e.g


class Logger {

public function __construct(){

....log start time to file;

}

public function __destruct(){

....log end time to file;

}

}

Then store it in your session. Then check for it on each page after
session_start() and create it if it does not exist?


Regards,

paul
Reply With Quote
  #3 (permalink)  
Old 12-16-2007
C.
 
Posts: n/a
Default Re: session length

On 15 Dec, 18:47, macca <ptmcna...@googlemail.com> wrote:
> Theres probably an easier way but couldn't you create an object that
> writes to a log the start time of the session (thus creation of the
> object) and then have a destructor that will write to the log the time
> when the session (thus object) is destroyed?
>
> e.g
>
> class Logger {
>
> public function __construct(){
>
> ...log start time to file;
>
> }
>
> public function __destruct(){
>
> ...log end time to file;
>
> }
> }
>
> Then store it in your session. Then check for it on each page after
> session_start() and create it if it does not exist?
>
> Regards,
>
> paul


Not holding out a lot of hope for this approach - I'd be surprised if
the default session reaper bothers with destructors. I'd go with
writing my own session handling functions.

C.
Reply With Quote
  #4 (permalink)  
Old 12-17-2007
macca
 
Posts: n/a
Default Re: session length

wasnt to keen on it myself...it was just a stab in the dark.
Reply With Quote
  #5 (permalink)  
Old 12-17-2007
Ron Eggler
 
Posts: n/a
Default Re: session length

But how can I recognize if someone just closed the Window? How is the
destructor function called?

Right now my script looks roughly like:

<?php
session_start();
if(isset($_GET['logout'])&& isset($_SESSION['id'])) {
$_SESSION['out-time']=getdate();
write (email); //to identify "session taker"
write(intime);
write(outtime);
session_destroy();
}
if (isset($_POST['email'])) {
save in time in session var;
save email in session var;
save session id in session var;
}
if (isset($_SESSION['email'])) {
/* session active content with logout link*/
?>
<br /><a href="<?php echo $_SERVER['PHP_SELF'];?>?logout=1">logout</a>
<?php
}
else {
?>
/* sessaion login conent with input field "email" */
} ?>

Isd this any usable? How would you recommend me going on this?
What I want: I wanna see which user looks for how long on my page without
closing the window -? how long the session is active. If the window is
closed now, no out time is being recorded... :(

Thanks for help!
Ron
Reply With Quote
  #6 (permalink)  
Old 12-17-2007
Michael Fesser
 
Posts: n/a
Default Re: session length

..oO(Ron Eggler)

>But how can I recognize if someone just closed the Window?


You can't. The session just times-out.

>Isd this any usable? How would you recommend me going on this?
>What I want: I wanna see which user looks for how long on my page without
>closing the window -?


Impossible. All you can get is the time between the first and the last
request made to your site. What happens after the last request is out of
your control. You can't tell whether the visitor is still reading your
page for an hour or if he's away already.

>how long the session is active. If the window is
>closed now, no out time is being recorded... :(


That's simply how HTTP works. Remember: It's a stateless protocol. Every
single request is completely independent from each other:

* user sends request
* server answers request
* user is gone

That's it, no more no less. Session are just a way to _partly_ overcome
this issue.

Micha
Reply With Quote
  #7 (permalink)  
Old 12-17-2007
Ron Eggler
 
Posts: n/a
Default Re: session length

Michael Fesser wrote:

> .oO(Ron Eggler)
>
>>But how can I recognize if someone just closed the Window?

>
> You can't. The session just times-out.
>
>>Isd this any usable? How would you recommend me going on this?
>>What I want: I wanna see which user looks for how long on my page without
>>closing the window -?

>
> Impossible. All you can get is the time between the first and the last
> request made to your site. What happens after the last request is out of
> your control. You can't tell whether the visitor is still reading your
> page for an hour or if he's away already.
>
>>how long the session is active. If the window is
>>closed now, no out time is being recorded... :(

>
> That's simply how HTTP works. Remember: It's a stateless protocol. Every
> single request is completely independent from each other:
>
> * user sends request
> * server answers request
> * user is gone
>
> That's it, no more no less. Session are just a way to _partly_ overcome
> this issue.
>

Michael,

Thanks for your response and right - I can record how long a user is looking
at my page by Javascript. Now I'm thinking if i can call a php script every
e.g. second that would update the information in a mysql table... but do i
actually need to display the "dummy php"page in a frame even tho there's no
html output or can i just call it"hidden" in the backkground somehow?

Thanks,
Ron
Reply With Quote
  #8 (permalink)  
Old 12-17-2007
Ron Eggler
 
Posts: n/a
Default Re: session length

Ron Eggler wrote:

> Michael Fesser wrote:
>
>> .oO(Ron Eggler)
>>
>>>But how can I recognize if someone just closed the Window?

>>
>> You can't. The session just times-out.
>>
>>>Isd this any usable? How would you recommend me going on this?
>>>What I want: I wanna see which user looks for how long on my page without
>>>closing the window -?

>>
>> Impossible. All you can get is the time between the first and the last
>> request made to your site. What happens after the last request is out of
>> your control. You can't tell whether the visitor is still reading your
>> page for an hour or if he's away already.
>>
>>>how long the session is active. If the window is
>>>closed now, no out time is being recorded... :(

>>
>> That's simply how HTTP works. Remember: It's a stateless protocol. Every
>> single request is completely independent from each other:
>>
>> * user sends request
>> * server answers request
>> * user is gone
>>
>> That's it, no more no less. Session are just a way to _partly_ overcome
>> this issue.
>>

> Michael,
>
> Thanks for your response and right - I can record how long a user is
> looking at my page by Javascript. Now I'm thinking if i can call a php
> script every e.g. second that would update the information in a mysql
> table... but do i actually need to display the "dummy php"page in a frame
> even tho there's no html output or can i just call it"hidden" in the
> backkground somehow?
>
> Thanks,
> Ron

I got an idea: I'll load my content into one frame (the content where i
wannas know the session time). And in the other frame (null frame) i load a
script that's writing data passed by GET into a db. The time is measured by
javascript in the content file and every minute i call my null frame php,
passing the time over in the url.
That should work fine.
*building it now* :)

Ron
Reply With Quote
  #9 (permalink)  
Old 12-19-2007
Onideus Mad Hatter
 
Posts: n/a
Default Re: session length

On Mon, 17 Dec 2007 21:01:40 GMT, Ron Eggler <NOREPLY@example.com>
wrote:

>Ron Eggler wrote:
>
>> Michael Fesser wrote:
>>
>>> .oO(Ron Eggler)
>>>
>>>>But how can I recognize if someone just closed the Window?
>>>
>>> You can't. The session just times-out.
>>>
>>>>Isd this any usable? How would you recommend me going on this?
>>>>What I want: I wanna see which user looks for how long on my page without
>>>>closing the window -?
>>>
>>> Impossible. All you can get is the time between the first and the last
>>> request made to your site. What happens after the last request is out of
>>> your control. You can't tell whether the visitor is still reading your
>>> page for an hour or if he's away already.
>>>
>>>>how long the session is active. If the window is
>>>>closed now, no out time is being recorded... :(
>>>
>>> That's simply how HTTP works. Remember: It's a stateless protocol. Every
>>> single request is completely independent from each other:
>>>
>>> * user sends request
>>> * server answers request
>>> * user is gone
>>>
>>> That's it, no more no less. Session are just a way to _partly_ overcome
>>> this issue.
>>>

>> Michael,
>>
>> Thanks for your response and right - I can record how long a user is
>> looking at my page by Javascript. Now I'm thinking if i can call a php
>> script every e.g. second that would update the information in a mysql
>> table... but do i actually need to display the "dummy php"page in a frame
>> even tho there's no html output or can i just call it"hidden" in the
>> backkground somehow?
>>
>> Thanks,
>> Ron

>I got an idea: I'll load my content into one frame (the content where i
>wannas know the session time). And in the other frame (null frame) i load a
>script that's writing data passed by GET into a db. The time is measured by
>javascript in the content file and every minute i call my null frame php,
>passing the time over in the url.
>That should work fine.
>*building it now* :)


....don't do that.

Just call the script like an image file using javascript, that's what
I do. Like nyah:

: A = "<img src='blah.php?screen_width=";
: B = screen.width
: C = "&screen_height=";
: D = screen.height
: E = "&color_depth=";
: F = screen.colorDepth
: G = "&os=";
: H = OS
: I = "&browser=";
: J = browser
: K = "&version=";
: L = version
: M = "&cookies=";
: N = cookies
: O = "&java=";
: P = java
: Q = "&flash=";
: R = flash
: S = "&flashversion=";
: T = flashversion
: U = "&time=";
: V = time
: W = "&ref=";
: X = document.referrer
: Y = "&raw=";
: Z = raw
: AA = "'>";
:
: document.write(A + B + C + D + E + F + G + H + I + J + K + L + M + N + O + P + Q + R + S + T + U + V + W + X + Y + Z + AA);

That way you don't need to bother using frames or multiple pages of
any sort.

--

Onideus Mad Hatter
mhm ¹ x ¹
http://www.backwater-productions.net
http://www.backwater-productions.net/hatter-blog


Hatter Quotes
-------------
"You're only one of the best if you're striving to become one of the
best."

"I didn't make reality, Sunshine, I just verbally bitch slapped you
with it."

"I'm not a professional, I'm an artist."

"Your Usenet blinders are my best friend."

"Usenet Filters - Learn to shut yourself the fuck up!"

"Drugs killed Jesus you know...oh wait, no, that was the Jews, my
bad."

"There are clingy things in the grass...burrs 'n such...mmmm..."

"The more I learn the more I'm killing my idols."

"Is it wrong to incur and then use the hate ridden, vengeful stupidity
of complete strangers in random Usenet froups to further my art?"

"Freedom is only a concept, like race it's merely a social construct
that doesn't really exist outside of your ability to convince others
of its relevancy."

"Next time slow up a lil, then maybe you won't jump the gun and start
creamin yer panties before it's time to pop the champagne proper."

"Reality is directly proportionate to how creative you are."

"People are pretty fucking high on themselves if they think that
they're just born with a soul. *snicker*...yeah, like they're just
givin em out for free."

"Quible, quible said the Hare. Quite a lot of quibling...everywhere.
So the Hare took a long stare and decided at best, to leave the rest,
to their merry little mess."

"There's a difference between 'bad' and 'so earth shatteringly
horrible it makes the angels scream in terror as they violently rip
their heads off, their blood spraying into the faces of a thousand
sweet innocent horrified children, who will forever have the terrible
images burned into their tiny little minds'."

"How sad that you're such a poor judge of style that you can't even
properly gauge the artistic worth of your own efforts."

"Those who record history are those who control history."

"I am the living embodiment of hell itself in all its tormentive rage,
endless suffering, unfathomable pain and unending horror...but you
don't get sent to me...I come for you."

"Ideally in a fight I'd want a BGM-109A with a W80 250 kiloton
tactical thermonuclear fusion based war head."

"Tell me, would you describe yourself more as a process or a
function?"

"Apparently this group has got the market cornered on stupid.
Intelligence is down 137 points across the board and the forecast
indicates an increase in Webtv users."

"Is my .sig delimiter broken? Really? You're sure? Awww,
gee...that's too bad...for YOU!" `, )
Reply With Quote
  #10 (permalink)  
Old 12-20-2007
Ron Eggler
 
Posts: n/a
Default Re: session length

Onideus Mad Hatter wrote:

> On Mon, 17 Dec 2007 21:01:40 GMT, Ron Eggler <NOREPLY@example.com>
> wrote:
>
>>Ron Eggler wrote:
>>
>>> Michael Fesser wrote:
>>>
>>>> .oO(Ron Eggler)
>>>>
>>>>>But how can I recognize if someone just closed the Window?
>>>>
>>>> You can't. The session just times-out.
>>>>
>>>>>Isd this any usable? How would you recommend me going on this?
>>>>>What I want: I wanna see which user looks for how long on my page
>>>>>without closing the window -?
>>>>
>>>> Impossible. All you can get is the time between the first and the last
>>>> request made to your site. What happens after the last request is out
>>>> of your control. You can't tell whether the visitor is still reading
>>>> your page for an hour or if he's away already.
>>>>
>>>>>how long the session is active. If the window is
>>>>>closed now, no out time is being recorded... :(
>>>>
>>>> That's simply how HTTP works. Remember: It's a stateless protocol.
>>>> Every single request is completely independent from each other:
>>>>
>>>> * user sends request
>>>> * server answers request
>>>> * user is gone
>>>>
>>>> That's it, no more no less. Session are just a way to partly overcome
>>>> this issue.
>>>>
>>> Michael,
>>>
>>> Thanks for your response and right - I can record how long a user is
>>> looking at my page by Javascript. Now I'm thinking if i can call a php
>>> script every e.g. second that would update the information in a mysql
>>> table... but do i actually need to display the "dummy php"page in a
>>> frame even tho there's no html output or can i just call it"hidden" in
>>> the backkground somehow?
>>>
>>> Thanks,
>>> Ron

>>I got an idea: I'll load my content into one frame (the content where i
>>wannas know the session time). And in the other frame (null frame) i load
>>a script that's writing data passed by GET into a db. The time is measured
>>by javascript in the content file and every minute i call my null frame
>>php, passing the time over in the url.
>>That should work fine.
>>*building it now* :)

>
> ...don't do that.
>
> Just call the script like an image file using javascript, that's what
> I do. Â*Like nyah:
>
> : Â* Â* Â* Â* Â* A = "<img src='blah.php?screen_width=";
> : Â* Â* Â* Â* Â* B = screen.width
> : Â* Â* Â* Â* Â* C = "&screen_height=";
> : Â* Â* Â* Â* Â* D = screen.height
> : Â* Â* Â* Â* Â* E = "&color_depth=";
> : Â* Â* Â* Â* Â* F = screen.colorDepth
> : Â* Â* Â* Â* Â* G = "&os=";
> : Â* Â* Â* Â* Â* H = OS
> : Â* Â* Â* Â* Â* I = "&browser=";
> : Â* Â* Â* Â* Â* J = browser
> : Â* Â* Â* Â* Â* K = "&version=";
> : Â* Â* Â* Â* Â* L = version
> : Â* Â* Â* Â* Â* M = "&cookies=";
> : Â* Â* Â* Â* Â* N = cookies
> : Â* Â* Â* Â* Â* O = "&java=";
> : Â* Â* Â* Â* Â* P = java
> : Â* Â* Â* Â* Â* Q = "&flash=";
> : Â* Â* Â* Â* Â* R = flash
> : Â* Â* Â* Â* Â* S = "&flashversion=";
> : Â* Â* Â* Â* Â* T = flashversion
> : Â* Â* Â* Â* Â* U = "&time=";
> : Â* Â* Â* Â* Â* V = time
> : Â* Â* Â* Â* Â* W = "&ref=";
> : Â* Â* Â* Â* Â* X = document.referrer
> : Â* Â* Â* Â* Â* Y = "&raw=";
> : Â* Â* Â* Â* Â* Z = raw
> : Â* Â* Â* Â* Â* AA = "'>";
> : Â* Â*
> : Â* Â* Â* Â* Â* document.write(A + B + C + D + E + F + G + H + I + J + K + L +
> : Â* Â* Â* Â* Â* M + N + O + P + Q + R + S + T + U + V + W + X + Y + Z + AA);
>
> That way you don't need to bother using frames or multiple pages of
> any sort.
>

That would have been a good idea... you're right but i already got it
working.... :) But - damn, i shoulda thought about this earlier as well -
hmm anyways i may get the chance to change it a lil later... it would be
nicer to have two files only instead one 3 :)

Thanks for the hint for sure and damn me! :)

Ron
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:41 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0