Current location: Hot Scripts Forums » Programming Languages » PHP » PHP Sessions Question


PHP Sessions Question

Reply
  #1 (permalink)  
Old 12-11-09, 07:26 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
PHP Sessions Question

I've been working with a friend on a web application and have a question about PHP sessions. Here's a little background:

His login system is session-based and doesn't use any explicit cookie-handling code; that is, whatever cookies are used are strictly the result of the PHP session handler. His app doesn't set or check any cookies anywhere.

He told me today that a user emailed him reporting that he could see other people's entries in his account, specifically in a "daily journal" page. I looked at the SQL that pulls the user's entries and I didn't see anything wrong with it, it looks pretty standard. Here's a sample:

$journalquery = "SELECT * FROM journal
WHERE user_id='$account_id'
ORDER BY journal_date DESC";


Pretty basic stuff, and I see no obvious way to go wrong. The "$account_id" is pulled from a session and matched to a column in the 'journal' table. The query is very straightforward, so I don't see how one user_id could be accessing another user_id, unless somehow the "$account_id" that's being pulled from the session is somehow getting mixed up or substituted.

As I said, the only cookies generated that might be used for the session are done by PHP itself, he's got nothing that sets a cookie or assigns values to a cookie, nothing like that, he's using just the native (automatic) PHP cookie handling that's used to maintain a session.

So, here's what I'm wondering: if his client is at a large company that's funneling all of the users through a single IP, and *another* user there happened to be logged into the same application (but under a different user_id), could the session(s) be getting mixed up, or somehow 'seeing' them both as the same user because the IPs are the same? Is this possible, or should I be looking somewhere else?

If this sounds like the cause, what's the best fix? Add some cookie handling code, or regen the sessions, or....? I'm not all that familiar with cookies and PHP...how much work would it be to add code to make a unique cookie for an existing login system that doesn't already have it?
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #2 (permalink)  
Old 12-12-09, 04:53 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Session ids aren't guarenteed to be unique. If it's a real busy server, the site has been up for a long time, and it's and real busy site, it's possible that people's session ids are duplicated.

It might be good to try using a session variable that has a hashed/encrypted/md5 version of the account id. When the person arrives at the site, it can get $account_id perform the same conversion and test for a match. If it's not a match, destroy the session.
Reply With Quote
  #3 (permalink)  
Old 12-13-09, 09:18 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by wirehopper View Post
Session ids aren't guarenteed to be unique. If it's a real busy server, the site has been up for a long time, and it's and real busy site, it's possible that people's session ids are duplicated.
It's not a very busy server, not a lot of traffic overall. I'm not sure what to think at this point.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #4 (permalink)  
Old 12-13-09, 01:15 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Ideas:

Check the size of the account_id field against the size of the session id.
Look around in the database, searching for patterns (many of the same account_ids, etc).
It's also possible that the user last used a publicly accessible computer and that someone posted on his account.
What happens if someone has disabled cookies?

I think the best fix is to find a unique identifier (other than session id) for each user, and use that to control access.

Interesting page: PHP 101 (part 10): A Session In The Cookie Jar
Reply With Quote
  #5 (permalink)  
Old 12-13-09, 06:37 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by wirehopper View Post
Ideas:
Check the size of the account_id field against the size of the session id.
Look around in the database, searching for patterns (many of the same account_ids, etc).
It's also possible that the user last used a publicly accessible computer and that someone posted on his account.
What happens if someone has disabled cookies?

I think the best fix is to find a unique identifier (other than session id) for each user, and use that to control access.
1) Hmmm, I'm not sure what checking the id size against the session id would do...could you elaborate?

2) All of the users have unique IDs (this is one of the first things I speculated about).

3) The user says he was on his own PC at work, so I don't think it was another user posting from his account. If he did, the data would still be there. After logging out and back in, the extra entries were gone.

4) If someone disables cookies, PHP automatically appends the SID to the end of the URL (and in some cases also rewrites the form HTML, from what I understand).
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #6 (permalink)  
Old 12-13-09, 07:53 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
I may have misunderstood the issue. I thought the account_id was the session id, that's why I suggested checking the size of the fields. If not - then it's not relevant.
Reply With Quote
  #7 (permalink)  
Old 12-14-09, 06:29 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
Quote:
Pretty basic stuff, and I see no obvious way to go wrong. The "$account_id" is pulled from a session and matched to a column in the 'journal' table. The query is very straightforward, so I don't see how one user_id could be accessing another user_id, unless somehow the "$account_id" that's being pulled from the session is somehow getting mixed up or substituted.
I'm probably gonna sound stupid (The only thing I'm good at. ), But, did the user see both journal entries? AS in theirs and another person's? The reason I ask is that if you are pulling by an account number, and seeing entries from more than one account, then either the INSERT statement is hosed, OR MySQL took a dump on ya. Probably not gonna be in the session's though.
Reply With Quote
  #8 (permalink)  
Old 12-14-09, 07:47 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Is the data stored in session files on the server, or in cookies on the clients?

How often are the session files cleared?

What's the lifetime of the cookies?

Reply With Quote
  #9 (permalink)  
Old 12-14-09, 09:10 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
Quote:
As I said, the only cookies generated that might be used for the session are done by PHP itself, he's got nothing that sets a cookie or assigns values to a cookie, nothing like that, he's using just the native (automatic) PHP cookie handling that's used to maintain a session.
Server Side storage.
Reply With Quote
  #10 (permalink)  
Old 12-15-09, 06:09 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Last idea - leading zeros that are getting lost for account_ids?

Good luck.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP or PHP which is better? nepala The Lounge 9 07-14-10 05:48 AM
Sports Pick Em racingboy20 Script Requests 3 06-18-10 03:12 AM
question about sending checkboxes values to php script? darksniperx PHP 3 10-13-07 01:03 PM
PHP multi-dimensional array sorting issue aqw PHP 2 06-24-05 11:09 PM
tables and PHP, odd question eq1987 PHP 3 07-04-04 12:30 PM


All times are GMT -5. The time now is 08:05 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.