PHP Post $_Cookie without curl to external site

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nauj
    New Member
    • Apr 2018
    • 1

    PHP Post $_Cookie without curl to external site

    Hi,
    I am trying to make an application to automate login and registry to a webpage without the user having to do it manually. The secuence should be something like this:

    a)--- Response.php (my php code) sends a post login request to 3rd party url
    b)--- Third party url sends back login cookie
    c)--- Response.php sends new post requesting registration for a class.

    The problem I have is, although I retrieve the cookie correctly I can't seem able to send it again on the 2nd interaction and
    the 3rd party server always gives me a "Logout" response.

    a) + b)
    Code:
    $url = 'https://aimharder.com/login';
    $data = array('mail' => 'useremail@gmail.com', 'pw' => 'userpass', 'login' => 'Log In');
    $data = http_build_query($data);
    
    $options = array(
      'http' => array(
        'header'  => 'Content-type: application/x-www-form-urlencoded\r\n',
        'method'  => 'POST',
        'content' => $data,
      ),
    );
    
    $context  = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    print_r ($_COOKIE);
    //This works ok
    This second part is when the problem begins:
    Code:
    $url = 'https://komcrossfit.aimharder.com/api/book';
    $cookie_amhrdrauth = 'Cookie: amhrdrauth=' . $_COOKIE['amhrdrauth'];
    $data = array('id' => '9043', 'day' => '20180331', 'insist' => '0');
    
    $data = http_build_query($data);
    $header = array ('Content-type: application/x-www-form-urlencoded\r\n' , $cookie_amhrdrauth);
    
    $options = array(
        'http' => array(
        'header'  => $header,
        'method'  => 'POST',
        'content' => $data
      )
    );
    I have tried many different variations to how to set up $header but none seem to send the cookie to the url and it always gives me a logout resonse.

    Please help!!
Working...