472,960 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,960 software developers and data experts.

problem fetching URL

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

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

<?php

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"];
if(isset($tmp["query"]))
$page .= "?". $tmp["query"];
if(isset($tmp["fragment"]))
$page .= "#". $tmp["fragment"];
$fp = fsockopen ($host, 80, $errno, $errstr, 15);

if($fp)
{
$response = "";
$header = "";

$request = "GET $page HTTP/1.0\r\nHost: $host\r\nUser-Agent:
Mozilla/4.0\r\nAccept:image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1\r\nAccept-Language:
en-us,en;q=0.5\r\nAccept-Charset:
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);

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

if(feof($fp))
break;
}
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:

<?php
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,
Andres
Jul 17 '05 #1
0 2023

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: martin.mrazek | last post by:
Hello, when installing the followin modulue from CPAN under MDK Linux I receive the error message (in the end of STDERR output) which I don't understand. Can you tell me what's wrong there?...
0
by: Bob | last post by:
I have an ASP.NET web application that has been running without any problems for a while. I recently transferred the site to shared hosting and had multiple users start to use the site. The problem...
8
by: Jack | last post by:
Hi, Here is my problem: I am logging in to a page, where the page retrieves a record from a database. The text boxes are used in the display formto let the users update the fields, if they...
15
by: Eric J. Holtman | last post by:
I feel like the answer to this should be blinding obvious. I also feel like it's probably an exercise in an undergraduate database design course. I'm off to google for an answer, but I figure I'd...
0
by: Shujun Huang | last post by:
Hi, I am working on converting Informix database to Postgre. I have one question for fetching records using PostgreSQL. The record I am fetching is a variable size text string. Before fetching...
22
by: Sandman | last post by:
So, I have this content management system I've developed myself. The system has a solid community part where members can register and then participate in forums, write weblogs and a ton of other...
1
by: Bhavesh | last post by:
Hi Bruce, Thanks For Reply. U were right, Needed to pass string , but also need to pass size of Data( instead of 16, passed actual length of data). So that worked for me & didn't get any...
2
by: SunshineInTheRain | last post by:
I'm trying to modify a long long code within a button click by make the insert/update/delete/select using the same transaction. Purpose is to make sure every operation can be rollback instead of some...
1
by: spatro | last post by:
Hi, I am trying to install DBD::mysql using the CPAN and I am facing the following error: cpan> install DBD::mysql CPAN: Storable loaded ok Going to read /root/.cpan/Metadata Warning:...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.