PHP Session Token

Hello,
I am reaching out to discuss a challenge I’m currently facing while developing a webpage. I have created a webpage using PHP, HTML, JavaScript, and CSS. The webpage allows users to submit input parameters, which are then processed to generate desired output results.
At this stage, I am encountering the need to handle multiple users accessing the webpage simultaneously. To provide further clarity, let’s consider a scenario where two users connect to the webpage at the same time. Each user aims to generate output results based on different input sets, and it’s essential to prevent their requests from overlapping.
I have been researching solutions, and one option that caught my attention is utilizing PHP session tokens. However, I am not an expert in web development, and I lack a comprehensive understanding of how to effectively address this issue.
I would greatly appreciate your insights and guidance on how to approach this challenge. If PHP session tokens are indeed a suitable solution, I would appreciate any advice or resources you could share to help me implement them correctly.
Thank you in advance

1 Like

Is this an atomic operation?

IE: If i submit the input, do i immediately (or at least, without sending another request) get the output?

If so, you dont need to do anything. The server processes each request independently, and responds to the correct requestor with their own response.

If not (there are several requests involved; possibly a job queue type system), a PHP session would handle the situation if the user contacts the server at least once every 15 minutes. Otherwise you’d need some other form of tracking (cookie, user login, etc).

Thank you for your reply.
Yes, it is indeed an atomic operation.
Upon filling out and submitting the input form, you receive the output immediately, without the need for any additional requests.
Unfortunately, this is not the case currently.
I attempted to perform two operations simultaneously, and I observed that the provided output corresponds to the last request that was made

That… doesnt make any sense, unless your code is manipulating a common resource (like a database). But if it’s manipulating a common resource, your problem won’t be solved by sessions.

I see…from your perspective, what would be the optimal approach for managing concurrent access by multiple users to the web application? The goal is to ensure that each user’s interactions and data remain isolated from one another

Without knowing what your server-side code is doing, I can’t answer that.

I understand your point. With the current structure of my web application, it primarily involves HTML, client-side JavaScript, and PHP scripts to manage user interactions and calculations.
The application’s server-side logic is responsible for processing user inputs, performing calculations, and displaying results. I hope this is what you asked about!

Your statement of the problem doesn’t help us without an actual example. Post the actual code that reproduces the problem, post what result you are getting from that code, and post what is wrong with that result.

3 Likes

You might want to look into the use of database transactions, to avoid situations for example two users are viewing the same record. User 1 updates and saves their changes, User 2 updates and saves their changes, potentially inadvertently undoing the changes made by User 1

1 Like

More specifically, the problem statement doesnt help because the statement as given would work normally. So there is something in your code or in your testing procedure that is causing a collision; without seeing the code, we cannot identify the problem.

1 Like

Are you using GET or POST to submit your data? Normally POST would be used.

If you are using GET then there is the possibility that the results might be cached. If multiple GET requests are submitted with the same parameters then you might be getting back the output of the first GET. You might never even be hitting your PHP code.

Seems unlikely but then again the OP seems oddly reluctant to provide details.

And this is one of those oldie but still goodie explanations of how the HTTP Request/Response cycle works. It might help to clarify what is going on in your app.

1 Like

I am using POST method to submit data.
I’ve been working with $_SESSION[‘user_token’], and after checking that the values returned from the uniqid function are indeed different, I realized that $_SESSION[‘user_token’] basically manages user sessions. As such, I’m wondering its direct suitability for effectively distinguishing between input and output data.!!
Given that, and given that I use a file to store input parameters and retrieve results, I’m not sure if creating a dedicated “session” directory would be responsible for placing the unique input and output files, thus helping with explicit differentiation and data handling.

Maybe you could post a minimalist version of your code. Keep it as simple as possible. Just one input parameter.

distinguishing between input and output data.!!
use a file to store input parameters and retrieve results

Neither of the above statements make much sense to me at all. Request comes in, you process it and then send a response back. No files or whatever needed.

It seems like you have something else going on.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.