470,849 Members | 1,196 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

problem fetching URL

I have a problem using a URL fetching algorithm (HTTP 1.0).

To download an image, I used to use this algorithm:


Header("Content-type: image/gif");

$referer = "http://www.creators.com/comics_show.cfm?comicname=mrh";
$url = "http://www.creators.com/1130/mrh/mrh1202g.gif";

$url = str_replace("&amp;","&",$url);
$tmp = parse_url($url);

$host = $tmp["host"];
$page = $tmp["path"];
$page .= "?". $tmp["query"];
$page .= "#". $tmp["fragment"];
$fp = fsockopen ($host, 80, $errno, $errstr, 15);

$response = "";
$header = "";

$request = "GET $page HTTP/1.0\r\nHost: $host\r\nUser-Agent:
ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\nKeep-Alive: 300\r\nConnection:
keep-alive\r\nReferer: ". $referer. "\r\n\r\n";

fputs ($fp, $request);

$header.=fgets($fp, 1024);

while (!preg_match("/\\r\\n\\r\\n$/",$header));

$tmp_response = fread ($fp, 2048);

while (!feof($fp))
$tmp_response .= fread ($fp, 4096);

echo $tmp_response;
@fclose ($fp);


while it works in *most* web sites, it does not work in creators.com
and in a few more web sites.

If I use curl:

Header("Content-type: image/gif");
$referer = "http://www.creators.com/comics_show.cfm?comicname=mrh";
$url = "http://www.creators.com/1130/mrh/mrh1202g.gif";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0");

curl_exec ($ch);
curl_close ($ch);

it works.

The problem is that I have no curl support in my web site. Any one can
detect the error in my code?

Thanks in advance,
Jul 17 '05 #1
0 1947

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by martin.mrazek | last post: by
reply views Thread by Bob | last post: by
15 posts views Thread by Eric J. Holtman | last post: by
reply views Thread by Shujun Huang | last post: by
22 posts views Thread by Sandman | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.