note 52033 modified in function.fsockopen by danbrown
| From: | danbrown@php.net | Date: | Sun, 20 Jul 2008 19:46:12 +0000 |
| Subject: | note 52033 modified in function.fsockopen by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142311@lists.php.net to get a copy of this message | ||
If you are using fsockopen to access webpage, but come across a redirect (Location: ) in the header
and want to find and follow the redirect as in this snippet:
<?php
while (!feof($fp)) {
$line=fgets($fp, 1024);
if (stristr($line,"location:")!="") {
$redirect=preg_replace("/location:/i","",$line);
}
}
?>
Then don't forget to <?php $redirect = trim($redirect); ?> before trying to follow this
new link as $redirect actually has a \r\n on the end of it and won't give you a valid path in
the next iteration otherwise. A six hour bug.
Saul Dobney
--was--
If you are using fsockopen to access webpage, but come across a redirect (Location: ) in the header
and want to find and follow the redirect as in this snippet:
while (!feof($fp)) {
$line=fgets($fp, 1024);
if (stristr($line,"location:")!="") {
$redirect=preg_replace("/location:/i","",$line);
}
}
Then don't forget to trim($redirect) before trying to follow this new link as $redirect
actually has a \r\n on the end of it and won't give you a valid path in the next iteration
otherwise. A six hour bug.
Saul Dobney
http://php.net/manual/en/function.fsockopen.php