lupus6x9 wrote:But sessions shouldn't be read from the browser URL.... If I go to script.php?s=123
and the script.php source code is:
<?php session_start(); if($_SESSION["s"] == "123") { echo "yay!"; } else { echo "nay"; } ?>
I don't get "yay." The session isn't a GET variable unless you set it. ...Right?
You're thinking of $GET. $SESSION variables can only (and should only) be set in your code.
Passing sessions explained.
OK, here's the deal, a PHP session (same for other languages/web servers too) is basically a random number that the server stores with server-side information and then sends a cookie to your browser. When your browser request additonal pages/images from your servers domain, it sends the cookie with the ID. I like to think of it as a safe combination. All the data iis stored in the "safe" (server) but you send the "combination" (session id) in your cookie with every subsequent request. Since the cookie is a temp cookie, when you close your browser the cookie is destroyed and the next time you request anything on the server, you get a new session.
And yes, you could initialize a session and set a variable when the form page loads and then check for that session variable when handling the form post. However, it's still very easy for a bot to hit your form and get a session cookie (just headers remember) and then just send that cookie in it's header when it does a post.
Okay, this is all based on my assumption that you want to make sure that a real human is using your form and that he or she is the same person and not a "man-in-the-middle." So what are your intentions with this script?