Session Variables - Sessions in PHP behaving strangely

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Session Variables - Sessions in PHP behaving strangely

u_c_iv
Hi. I am part of a development team working in PHP and MySQL. The site is using SSL, and users have to log to use the site. When users log in, their important details are retrieved from the database and stored in session variables (functionality in the site is permissions specific). Lately, sessions are "disappearing" for no apparent reason. Users will log in, and at some point (the length of time will vary unpredicatably) the sessions will lose their value (the variables are empty) and this causes the site to evict the user. This is very frustrating for the user but moreso for the development team who is struggling to understand why this happens. The STRANGEST part is that the site is hosted in a city in Australia, the users a predominantly in another city in Australia, and I am in Charlotte. I have NEVER been able to replicate the problem on the live server or my localhost test machine. I had some friends in the same city in Australia try to access the site, and they aren't able to replicate the error... ?!?!? Those of you who debug will appreciate the hopelessness of trying to solve an error when you can't even get it to trip up!

This is all I know - sessions are losing their value and I have no idea why. I've coded a work around for the PHP garbage collection function and that was working well for some time.

I have checekd the code, and it isn't the problem (I think).

Can ANYONE help me?

 

 

 


Reply

WindAndWater
I can't think of any reason why the session variables would loose scope unless they were overwritten/overloaded. If you can't find any evidence of that in your code you might consider temorarily switching to using session cookies until you resolve the problem.

Reply

Spectre
Unless you explicitly destroy the session (eg. by prematurely calling session_destroy()) or PHP is unable to determine the session's owner, this shouldn't happen. Generally speaking, PHP will either use a cookie to indicate a session's owner or append the session ID to all links within the page (eg. a link to '/page.html' may become '/page.html?PHPSESID={32-byte MD5 hash}'). If it using the second method, perhaps it is losing track of session owners if the link is unable to be modified - are you using irregular HTML or can you think of some other problem that may affect it in this way?

Anyway, try setting and/or checking when the session is set to expire with the session_cache_expire() function. It probably wouldn't hurt to further explore PHP sessions either; perhaps it's your server configuration or a problem within your code that you aren't aware of.

Reply

u_c_iv
Hi guys. Thanks for your input. I just had a very interesting accident...

What was really bothering me was that code doesn't morph, right? So if there is faulty code on one server, it will be faulty on another server. The code was working exactly as intended on my local machine, and certain users (in certain locations) never had the error, and yet a lot of people were consistently having the error! No matter how I tried to replicate what the error-prone users were doing, I just didn't get the error.

Then.

I bought a laptop, and I was setting it up with a development environment, and all the usual stuff you need on a computer. The thing I didn't have was firewall/virus protection. So I bought CA eTrust Internet Security Suite and installed it. Because I want my two machines to share resources (see my OTHER post where I'm having no luck in THAT arena) I set my home network to be a trusted zone. It all installed fine and I restarted the machine to do some work.

Then when I opened up my localhost site, I had the EXACT SAME ERROR as the users were having in Australia!! I couldn't believe it. I uninstalled the Security Suite, restarted the machine, and the error was gone. Re-installed the Security Suite - you guessed it. Errors.

Bottom line... my signal chain is ISP -> Modem -> Wireless Router -> PCs. So in setting my home network (including the router) as a trusted zone, it prevented the sessions holding their value. If I set the home network as a Internet Zone, then it works fine - therein is my home network problem... shared resources need to eb in a trusted zone!!

I did an online help-chat with someone from CA, and they said that the reason for this problem is that trusted zones are treated with more caution (?! I thought they were TRUSTED?!?!) and that was the interference with the session values. They confirmed that the problem my users in Australia were experiencing are not related to the code.

I have temporarily incorporated cookies as a backup plan (as suggested) and so far so good. I'll let you all know if it keeps up...

 

 

 


Reply

u_c_iv
Hi again,

I'm sorry to report that the cookie-solution that I tried to implement was of no effect. The cookies are created (as are the session variables), but for some STRANGE reason, they are getting deleted. I'm almost 100% positive that it is outside of the control of the PHP code, so I have to leave it alone for now and try to find out what sorts of measures ISPs use to stay secure.

Thanks again for your help. I will let you know if I find anything interesting.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Recent Queries:-
  1. session variable interference asp - 795.16 hr back. (1)
Similar Topics

Keywords : session, variables, sessions, php, behaving, strangely

  1. Counting Variables?
    (4)
  2. Something I Discovered With Sessions [php]
    (4)
    Hello All, I've been doing a lot of PHP programming since I last posted here. I've run
    across two security related things with sessions that you may or may not know about. The first one
    pertains to the session id, or the id that PHP assigns each computer when a session is created.
    This id is either stored in a cookie (search for PHPSESSID) or through the URL as GET data.
    Remember that all session data is stored server side; this ID is the only thing that PHP will use to
    differentiate your computer from someone else's. While I was programming for Plug ....
  3. Php Sessions And Post Variables Issues
    My script dosent seem to work as intended (1)
    You can test it out for yourself at http://sonesay.trap17.com/application.php I've been
    working on this page locally and it seems to be working fine but when I upload it to my trap17
    account the post variables dont get saved properly. Fill in some fields and submit it, the form
    will come up as a empty field yet when you resubmit it without any modifications and the data you
    entered in orginally will now magically appear, resubmit it again and it will be gone. This is
    really annoying as I have no clue why it would be doing this when it seems to work fine locally.....
  4. <?php ?> Unique Visitors Script
    Flat file unique visitors script (no sessions) (2)
    This is really simple script. Well at least this part is, but it could be extendable. Only problem
    is that it's not really for massive websites with hundread of visitors a day, but rather for
    small ones. But it is a good script to figure out how to make a visitor counter script. Anyway
    here's the snippet. CODE <?php function getVisits($variable) {
        $visits = array();     if ($handle =
    opendir('stats/')) {     while (false !== ($file =
    readdir($handle))) {  ....
  5. Php Session
    (6)
    Okay, I just got all my site stuff transferred over to Trap17, so I'm ready to resume coding.
    I'm currently working on my members' pages, and wish to use the PHP Session tags and include
    it in a function so that on every page, I just include the function to check and see if that user is
    still logged in and is allowed to view that page. Somebody told me I need to use the isset( blah
    blah blah and check to see if they were logged in from the login page (not sure how to do that),
    then query the $_SESSION so I can check the 'userlevel' to check if ....
  6. Php-fusion Cms
    No session_start() used? (3)
    A while back i was looking for free hosting and a forumn suite for my own comunity. I ended up using
    hostingdirect.co.nz and php-fusion from http://php-fusion.co.uk It was pretty easy to setup and
    run. But my site required more specific functions other then generic CMS could offer and I wanted to
    learn PHP so I start reading tutorials and such to learn. I was working on them locally and they
    seem to run fine on my own server. When i upload my own site to the hostingdirect site I find they
    do not have safe_mode off. I got an error in my index.php file when i try and ru....
  7. Sending $_get[] Variables To An Application
    (3)
    I'm trying to work out if it is possible to send variables to a application on server. E.g
    send the variable of id which is equal to 10 to an application - test.exe?id=10 Any ideas to see if
    this is possible?....
  8. How Do I Pass Php Variables From A Url To A Form?
    I'm about read to tear my hair out with this one (5)
    Ok, what I need is for users to be able to select what address they want (e.g. mydomain + .com),
    click submit that then sends the variables 'domain' and 'ext' through the URL e.g.
    mywebsite.com/example.php?domain=mydomain&ext=com (the variables being mydomain and com) where they
    are displayed in a form mail as "Domain Selected: mydomain.com" that can then be submitted and sent
    to an email. In my form so far I have CODE <input name="domainname"
    type="text" id="domainname" value ="<?php echo "$domain"; ?....
  9. Storing Session Variables Generated Dynamically
    (3)
    i have many pool (quiz) modules on my site with the information taken from a database. The modules
    are processed by the same function with different parameters and i need to save the pool's
    status to prevent a user vote several times. I do this setting $_SESSION to 1 , variable
    being the name of the quiz, which is taken from the database. So i get to having a code like this:
    .................... $name= $row->quiz_name; $_SESSION =1 The problem is that if
    i call $_SESSION from another part of the site (another page) the variable is al....
  10. Php - Can Anyone Tell Me What "session" Actually Do?
    (5)
    php - can anyone tell me what "session" actually do? I was looking at this page
    http://www.w3schools.com/php/php_sessions.asp this paragraph here: A PHP session solves this
    problem by allowing you to store user information on the server for later use (i.e. username,
    shopping items, etc). However, session information is temporary and will be deleted after the user
    has left the website. If you need a permanent storage you may want to store the data in a database.
    Especially this part below: QUOTE A PHP session solves this problem by allowing you to store
    user in....
  11. Using Sessions Instead Of Cookies, Help Please
    (1)
    This is a simple code to register and login.. this uses cookies.. i want to use sessions instead..
    can someone tell how i can do it ? config.php CODE <?    ob_start(); // allows you
    to use cookies    $conn =
    mysql_connect("localhost","USER","PASSWORD");   
    mysql_select_db(DATEBASE) or die(mysql_error());    //fill in the above
    lines where there are capital letters.    $logged = MYSQL_QUERY("SELECT * from users
    WHERE id='$_COOKIE[id]' AND password = '$....
  12. Sessions And Login
    Without Cookies (5)
    Hi, I have a login script i made using PHP sessions and MySQL. It works fine but there is a
    problem. As you know Sessions are stored in Cookies by PHP. So if someone has switched Cookies off
    then no sessions will work. How to solve this problem ? Please help me. Thanks and have a good
    day. ....
  13. Converting Characters In A Variable To Individual Values In An Array
    turning variables into arrays (2)
    Say I have a variable such as $nav_item and it had to contents Home . IE: CODE
    $nav_item = 'Home'; How would I make so that $nav_item was an array and
    had the following contents? CODE $nav_item = array ('h', 'o',
    'm', 'e'); With the case changing (ie H would become h and U
    would become u ) EDIT: Okay found out that I could change the case with
    array_change_key_case ($nav_item, CASE_LOWER); ....
  14. Transfer Variables To Another Php Script
    (8)
    Hello, I've one registration page where the users fills in their information, is it possible to
    trasnfer the things the fill in on the registration page to another script that does someting and
    returnes something to the first page like true/false and then the registration gives an error
    messange if the other php script returned false? Something like the script "activates" another
    script that does something and returnes the result back to the original script. Best Regards ....
  15. Php Sessions
    Multiple users using the same login (2)
    Hi, I'm realtively new to PHP and I'm considering creating some login functionality.
    However I want a group of users to use the same loginname and password. They will be loggin infrom
    different machines. The users will know they are sharing the account. Can anyone give me an idea
    of what kind of effect this might have on my sessions? Will it create any odd hiccups or other
    strange things?....
  16. Session Start() Problem
    Need help with an error (5)
    Warning: session_start(): Cannot send session cache limiter - headers already sent (output started
    at /home/ridouan/public_html/Reviews.php:5) in /home/ridouan/public_html/Reviews.php on line 6
    Can't seem to fix the error (im a php noob) So i'd appreciate some help /smile.gif'
    border='0' style='vertical-align:middle' alt='smile.gif' /> If you need it: Gamer Online then
    click on the Reviews link....
  17. How Long Do $_post Variables Stay Stored?
    (6)
    let's say that for whatever reason, let's say for a survey, i want to make a quiz like
    w3schools.com has, only with PHP. i would want to put all the questions on different pages, also
    like w3schools. could each of the submissions stay stored inside PHP's $_POST for 20
    pages? if not, how could i get around it? PS. i really don't know anything about ASP other than
    the fact that w3schools uses it. so please don't explain to me with ASP-specific terms.......
  18. Quick Question About Session Vars
    something I can't find anywhere (1)
    Can you save stuff like classes and arrays in sessionsvariables?....
  19. Sessions
    heeeelllllp!!!!!! (8)
    Hi. Im making a flatfile chatroom. Ive been making it about a month because I dont understand the
    sessions. When the user enters the room he/she has to enter a nickname. But when the user enters a
    message the chatroom "forgets" the nickname. Ive been messing around with sessions but I cant get em
    to work. Session_start(); thingy is in the right place (at the top). Ive looked through about 10
    diferent tutorials but they were useless. How do I make it to pass the nickname variable to multiple
    pages? And please dont tell me to search google or use php.net because ive alread....

    1. Looking for session, variables, sessions, php, behaving, strangely

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for session, variables, sessions, php, behaving, strangely

*MORE FROM TRAP17.COM*
advertisement



Session Variables - Sessions in PHP behaving strangely



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE