Please excuse the poor title. I am a total beginner and don't know the right terms to make it better.
I am trying to POST form data using PHP.
My problem is that before i POST the form data i need to get a value from the form, that is changing each time i request the page.
Please notice the second input, the value is auto generated and is a random number each time i request the form.
Here is my form.php:
<?php 
if(!isset($_REQUEST['submit_btn'])){
echo '  
<form action="'.$_SERVER['PHP_SELF'].'" method="POST">
   <input type="text" name="user_name" id="user_name">
   <input type="hidden" name="a_random_password" value="'.(rand(10,100)).'">
   <input type="submit" value="submit" name="submit_btn">
</form>';
}
if(isset($_REQUEST['submit_btn']))
    {
       $user_name= $_POST["user_name"];
       $a_random_password = $_POST["a_random_password"];
       echo "Your User Name is:". $user_name;
       echo "<br> and your Password is : $a_random_password;
    }
?>
And my post.php
<?php
$url = "http://test.com/form.php";
$data = array(
'user_name' => 'John',
'a_random_password' => 'xxx',
'submit' => 'submit'
);
$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',    
        'content' => http_build_query($data)        
    )
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { echo "Error"; }
var_dump($result);
?>
So how do i get the a_random_password value and submit it along with the form in a single request, else the password wont fit with the user name.
 
     
    