02.
03.
$ch
= curl_init();
04.
curl_setopt(
$ch
, CURLOPT_HEADER, true);
05.
curl_setopt(
$ch
, CURLOPT_RETURNTRANSFER, true);
06.
07.
08.
curl_setopt(
$ch
, CURLOPT_URL,
$urls
);
09.
$out
= curl_exec(
$ch
);
10.
11.
12.
$out
=
str_replace
(
"\r"
,
""
,
$out
);
13.
14.
15.
$headers_end
=
strpos
(
$out
,
"\n\n"
);
16.
if
(
$headers_end
!== false) {
17.
$out
=
substr
(
$out
, 0,
$headers_end
);
18.
}
19.
20.
$headers
=
explode
(
"\n"
,
$out
);
21.
foreach
(
$headers
as
$header
) {
22.
if
(
substr
(
$header
, 0, 10) ==
"Location: "
){
23.
$target
=
substr
(
$header
, 10);
24.
echo
$target
;
25.
}
26.
}