Is there a better way to keep track of session variable creation/access throughout different pages?
Here's what I am working on. At my website I have multiple processes with each one containing multiple steps. Now in one of the processes, there is an error checking routine executed before proceeding to the next step of that process. A session var is set indicating the error status and it will either redirect back to the referrer or display the next page's contents.
Now this kind of functionality, I believe, is common throughout web development. The issue that is occurring is that session vars are left around and are not being cleaned up properly. At times this introduces undesired behavior. My website is growing and I find that I am requiring more and more session vars to keep track of different system and error states.
So I was thinking about creating a kind of "session variable keeper" to keep track of session var usage. The idea is fairly simple. It will have the notion of a context (e.g. registration process) and allow access to a predefined set of session vars within that context. In addition, the var and context will be paired with an action to proceed to some form of event handling.
开发者_如何学JAVASo if you haven't noticed I'm new to web development. Any thoughts or comments on the idea that I am proposing would be greatly appreciated. The back-end is written in PHP/MySQL.
In PHP, Sessions are stored as objects (aka arrays). And with those you can store multiple dimensions of data. So why don't you start storing your session variables in the following format:
$_SESSION[$context][$var] = $value;
// Example: $_SESSION['registration']['laststep'] = 4;
It's best not to use session variables. All requests to your web application should contain enough information to be handled without additional server side state. This is the basis of the RESTful architectural style.
More Discussion at the website for an excellent open source RESTful PHP framework that you might want to look into.
精彩评论