provide 'session' option to z_fetch_url to assist with remote fetches requiring magic auth

This commit is contained in:
zotlabs
2017-02-27 23:48:54 -08:00
parent df6e75e1d6
commit fa944fc526
2 changed files with 5 additions and 1 deletions

View File

@@ -91,6 +91,10 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) {
@curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60));
}
if(x($opts,'session') && strpos($url,z_root()) === 0) {
@curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Cookie: PHPSESSID=' . session_id() ]);
}
if(x($opts,'http_auth')) {
// "username" . ':' . "password"
@curl_setopt($ch, CURLOPT_USERPWD, $opts['http_auth']);