I'm writing a script that sends a GET request, then assigns the value of the Location
header in the response to a variable, This is my script so far.
<?php
$url = "http://www.example.com/";
$opts = array('http' =>
array(
'method' => 'GET',
'max_redirects' => '0',
'ignore_errors' => '1'
)
);
$context = stream_context_create($opts);
$stream = fopen($url, 'r', false, $context);
$headers = stream_get_meta_data($stream);
?>
this script saves the resp headers to an array , now when trying to call any object in the above array i get an error, for example
echo $headers[3];
i get the following error:
Notice: Undefined offset: 3 in /home/xxxxx/public_html/xxxx/file.php on line 24
here's what i want to do but in python:
import requests
url = "https://test.com/file.php?next=google"
headers = {"Cookie":"asd=123"}
req = requests.get(url,headers=headers,allow_redirects=False)
print "<img src=\""+req.headers['Location']+"\" >"
solved by using
echo echo $headers["wrapper_data"][0];
instead of
echo $headers[0];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.