Re: trying to capture url data to a stream, with a twist...
| From: | Ronan Chilvers | Date: | Fri, 23 May 2003 13:32:53 +0000 |
| Subject: | Re: trying to capture url data to a stream, with a twist... | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-27989@lists.php.net to get a copy of this message | ||
Hi Andy
Try this one using fsockopen...
function random_website()
{
$site = "random.yahoo.com";
$page = "/fast/ryl";
$open = fsockopen($site, 80, $errno, $errstr);
if ($open) {
fputs($open, "GET $page HTTP/1.0\r\n\r\n");
$data = "";
while (!feof($open)) {
$data .= fgets($open,1000);
}
fclose($open);
} else {
echo "No Socket<BR>";
}
$search = ereg("Location: (.*)", $data, $content);
return $content[1];
}
Seems to do the trick ...
:-)
Ronan
e: ronan@thelittledot.com
t: 01903 739 997
w: www.thelittledot.com
The Little Dot is a partnership of
Ronan Chilvers and Giles Webberley
On 23 May,2003 at 3:48 Andy Green wrote:
> i'm trying to capture output from a remote url(random.yahoo.com/fast/ryl)
> and use it on my site. however, the remote url output always leads with a
> Status 301 code, then outputs the data i want. as a result, the fopen()
> function thinks that the connection to the remote url fails, and goes no
> further.
>
> below is the code snippet i'm using to try and capture the stream, to no
> avail...
>
> function random_website()
> {
>
> $site = "http://random.yahoo.com/fast/ryl";
> $open = fopen($site, "r");
> $search = fread($open, 50000);
> fclose($open);
> $search = ereg("Location: (.*)", $search, $content);
> return $content[1];
> }
>
> ultimately, what i want is the data given after the 301 code, which is a
> random url generated when you load the remote url.
>
> any thoughts or suggestions are welcome.
>
> thanks
>
> green
>
>
>