LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-04-2002, 10:28 AM   #1
lhoff
Member
 
Registered: Jun 2001
Location: Chicago
Distribution: Mandrake 10.0 Official
Posts: 181

Rep: Reputation: 30
PHP session control


I need to unregister and destroy a session for a web app I'm developing.

I'm not using cookies (that's a requirement); the session currently persists across multiple PHP documents. But, when the user either (a) leaves the current web directory or (b) closes the browser window, I need to unregister and destroy the session.

I thought about putting this into an onunload event, but that would destroy the session while the user is just moving between pages.

Anybody have any suggestions about how to do this? Thanks!
 
Old 05-06-2002, 04:41 AM   #2
gene_gEnie
Member
 
Registered: Aug 2001
Location: London UK
Distribution: Redhat 7.2, soon to be LFS!
Posts: 42

Rep: Reputation: 15
Hi,
not totally sure about either of these but here goes:

for (b) Wont the session be killed automatically when the user closes the browser window?

for (a) By web directory, do you mean the part after the domain?
i.e. www.linuxquestions.org/questions
or
www.linuxquestions.org/different_dir

with questions or different_dir being the relevant parts.

If so, you could test the HTTP_REFERER against the current URL using some regex. If the dir part is different, kill your session, if not just continue as normal.

????

Sounds easy eh.
Im sure that would work though.

Hope that helps

Martin
 
Old 05-06-2002, 09:45 AM   #3
lhoff
Member
 
Registered: Jun 2001
Location: Chicago
Distribution: Mandrake 10.0 Official
Posts: 181

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by gene_gEnie

for (b) Wont the session be killed automatically when the user closes the browser window?
No: I can close the browser, launch a new one, scroll down the cached addresses to the URL that has my old session number in it and select it. I'm back in my old session, logged in. That's what I need to prevent.

Quote:
for (a) By web directory, do you mean the part after the domain?
i.e. www.linuxquestions.org/questions
or
www.linuxquestions.org/different_dir
Yep. I'll give the HTTP-REFERER method a try, though I've not used it before.

Thanks!
 
Old 05-06-2002, 12:25 PM   #4
gene_gEnie
Member
 
Registered: Aug 2001
Location: London UK
Distribution: Redhat 7.2, soon to be LFS!
Posts: 42

Rep: Reputation: 15
i had a look round the net for an example on how to trap a closing window and it seems lots of people have had the same problem.

this link will take you to a msg board with a couple of suggestions - none of them trivial i reckon.

http://216.239.51.100/search?q=cache:
Phx8sc62_n8C:p2p.wrox.com/archive/javascript/
2001-09/46.asp+trap+browser+closing+with+javascript&hl=en

One guy said that you cant trap the user closing the window with the X button (top right hand corner etc) so what you have to do is trap everything else that may be a problem, in your case:
a refresh or moving to a different page within the same directory.

Then, set a flag to true, only if it is none of these events was fired.
hmmmm....

Have a look at that msg board, there is some javascript on it that you could maybe adapt, - javascript being the way to accomplish this probably.

hth

Martin

p.s. sorry about messed up URL. I couldnt get LQ to stop parsing it in funny ways. (i.e inserting smileys or newlines or completely ommiting some of it)

Last edited by gene_gEnie; 05-06-2002 at 12:29 PM.
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Are PHP session variables held in memory when you leave a PHP site? Locura Programming 11 11-16-2008 08:37 PM
how to recover control session ? superstition Linux - General 1 08-23-2005 06:57 PM
php session richard22 Programming 2 10-26-2004 05:50 AM
Enable session on PHP 4.4.3 robertoneto123 Linux - Newbie 1 04-13-2004 01:45 PM
php session problems jogurt666 Linux - Software 0 11-19-2003 04:06 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration