I'm trying to download some web page with php code.
$context_params = array('http' => array('method' => 'GET',
'user_agent' => 'Mozilla/5.0',
'timeout' => 1,
'header' => "Accept-language: en".
"Cookie: site=blabla1234567cookie;
__cf=cookie12345678;
PHPSESSID=phpsessidcookie;"));
$context = stream_context_create($context_params);
$html = file_get_contents($url, FALSE, $context);
Web server checks user by verifying cookies. I have inserted the correct client cookies in context, however, file_get_contents returns blank page as soon as PHPSESSID expires(~1 hour?). I tried to delete PHPSESSID cookie on web browser, and as soon as I loaded webpage it generated new PHPSESSID cookie. It didn't require any relogin tho. Then I tried to remove PHPSESSID cookie on script, but now file_get_contents returns blank page.
I tried to check this thread, but it didn't help anyhow. It still returns blank page, and I can't print context array with print_r()/var_dump/echo as soon as I insert session_id() and session_name() in script. (too large?)
session_write_close() makes no difference.
If I remove all cookies then it loads the page without any problems, but I'm not logged in.
I tried to read response for blank pages with var_dump/echo, and they both return BLANK on $http_response_header right after file_get_contents.
In theory, PHPSESSID can be generated by remote server and sent to client according to his cookies and IP address (that explains why its working on my machine, but doesn't work on my VPS). But isn't PHPSESSID supposed to be generated on client machine independent of your own IP address?
Question: How do I generate/set/renew new correct PHPSESSID for context for PHP script automaticly?
Edit: I want to use file_get_contents. Not interested in cURL solution at all.