Jump to content

different users interfering with each other


rghollenbeck
Go to solution Solved by mac_gyver,

Recommended Posts

When I run my quiz program from one computer, it works okay.  If I run it from another computer it works okay there too.  But when I'm running both computers on the same program, they interfere with each other--the quiz running on one computer is waiting for an answer that was just asked on the other computer, etc.

 

My guess is that by turning ALL my variables into session variables, I will solve that particular problem.  Is this correct? Or are there other things I need to do to prevent multiple users from confusing any server-side PHP-based quiz? 

 

Thanks

Link to comment
Share on other sites

  • Solution

each request to a server for a web page is completely separate from all other requests for that same (or a different) page and session data is separate for each different browser. the only way of getting a mixing of data is if there is more than one instance or tab of a single browser running on the same computer. all instances/tabs of the same browser on any one computer would use the same session id and access the same session data.

 

it would take knowing what your code is in order to determine what it is doing that could account for the symptom.

 

best guess, your code is storing something on the server in a file or database and is not retrieving the correct values based on who the the visitor is.

 

edit: i did just think of a way of two separate computers interfering, but this would require that the session id be passed in the url and you somehow sent the url containing a session id from one computer to the other.

Edited by mac_gyver
Link to comment
Share on other sites

Why do you want to use a session if you're planning to use the same user account from different machines or browsers? The session's life is expired (delete) when you close a browser window and the current unclosed session data will be overriden if someone try to start a different session with the same account. You need to use cookies with expired time to do that and then that the same cookie data is going to be sent to the same user with different machines (browsers). You have to show us your own script as well.  

Edited by jazzman1
Link to comment
Share on other sites

Wow!  It looks like it's mac_gyver to the rescue once again!

 

best guess, your code is storing something on the server in a file or database and is not retrieving the correct values based on who the the visitor is.

 

 

Not only did you solve my problem, you answered the question I didn't know how to ask.  Yes, Prior to today, I didn't even know about session variables; I knew about cookies, if you remember my original question from yesterday.  I was storing variables in text files on the server.  Okay, here's a scenario:

 

User A gets a question posed to her and the question number is stored in a text file.

User B comes along and does the same thing, changing the data in the text file.

User A answers the question that has been changed by user B.

 

See?  No bueno.  I cannot store it in a text file.  The answer to my question is, "Yes." I need to replace that text file with a session variable. That will fix the problem.

 

Thank you again!

 

To jazzman1's question about why I would want to do this, I was only testing my code against possible problems.  If I hadn't used two separate computers and/or two separate instances such as another browser at the same time, I might not have discovered the error in my thinking.  I would have discovered it after the quiz hit the streets.  That would have been more embarrassing.

Edited by rghollenbeck
Link to comment
Share on other sites

actually, you could store the values in a file, which would require that you write a bunch of code, with file locking,... -

 

you can store these in a flat-file database (i.e. text file), by each line in the file having more than one field - a username, the score, ...

 

 

you would need to identify the visitor, using a unique token instead of an actual username, but this is what the session id is, so yes, it's easier to just use session variables.

Link to comment
Share on other sites

 


The session's life is expired (delete) when you close a browser window and the current unclosed session data will be overriden if someone try to start a different session with the same account. 

 

That's not really what happens. Sessions are identified by the sessionid which is stored in a cookie. By default, the cookie is setup to be forgotten when the browser closes, but this can be easily reconfigured at scriptlevel and serverlevel.

A few years ago I had the curiuos problem that sessionid's were being re-used on the same browser; opening and closing forgot the cookie but visiting the page produced the exact same sessionid again.

 

 


session data is separate for each different browser

 

As long as the sessionid is different, which PHP tries to guarantee by no issueing sessionids for which there is already a file on disk. If the cookie doesn't delete, or the sessionid is stored in a URL, it's perfectly possible to use the same session on many different computers at the same time.

 

 


See?  No bueno.  I cannot store it in a text file.  The answer to my question is, "Yes." I need to replace that text file with a session variable. That will fix the problem.

 

Depending on what you want to do with the data it might even be a good idea to use a database, so you don't lose any data when people abandon the quiz before it's completed. (this can be important to know; if many people leave the quiz at the same question then that question may be offensive to them or the quiz may simple break and not allow them to answer).

 

Also, for testing, look into Selenium. That's a sort of recorder that can record and playback a browsing session, and check the content of a page while doing it. That allows you to record filling out the quiz and later test if the quiz still works as it did when you recorded it. It saves you from having to go through the entire quiz manually just to see if a change in the final page looks ok.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.