I have a php script that will make a series of requests on a server. The first request will be a login request.
The problem is that file_get_contents seems to create a new session every time, so how can I make it session aware?
Here is my function which needed to make it remember session:
function request($method, $data, $url){
    $options = array(
        'http' => array(
            'header'  => "Content-type: application/x-www-form-urlencoded\r\n"."Cookie: ".session_name()."=".session_id()."\r\n",
            'method'  => $method,
            'content' => http_build_query($data),
        ),
    );
    $context  = stream_context_create($options);
    session_write_close();
    $result = file_get_contents($url, false, $context);
    return $result;
}