Let’s say I am building an web app that is connecting and basically parsing another website. my question is, if you are posting (let’s say were using jquery/ajax via shorthand $.post) with a php script that has multiple variables. Take for example this script:
$user = $_POST['user'];
$pass = $_POST['pass'];
if(isset($user) && $user !== null){
if(isset($pass) && $pass !== null)
echo 'true'
else
echo 'false';
}
Now our app is really weird (just an example) and decides to submit the user and password to the script at different intervals via jQuery’s $.post, which will basically in an ajax shorthand submit to script and retrieve data. Our app is going to submit the username the user enters first, but just to piss the user off, in a separate post call it submits the password five minutes later.
So in a visual way
$.post('script.php',{user: 'username'}) -> posts to the script, but doesn't
return anything, as in this case it would return false
<em>5 minutes later</em>
$.post('script.php',{pass: 'password'}, function(data){
alert("data returned: " + data);
});
Would the script remember the previous username post variable passed if it all originated from the same page? or would it forget it and not run at all (for username is not set)?
basically my overall questions is, can you submit different post variables to a php script from the same page at different times and will they work together in the script or no?
No. The
$_POSTarray ‘s context changes with each request, in that it will always contain the last POSTed key – value pairs. You may be after a mechanism for preserving state, such as the$_SESSIONarray, which of course you need to initialize and transfer values to yourself.