Click here to get back home

cURL return last effective url, but don't download content?

 HomeNewsGroups | Search | About
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
cURL return last effective url, but don't download content? Mikhail Kovalev 08-01-2008
Posted by Mikhail Kovalev on August 1, 2008, 4:47 pm
Please log in for more thread options
Suppose I have something like this

$resource = curl_init();
curl_setopt($resource, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($resource, CURLOPT_URL, '......');
curl_exec($resource);
$lastUrl = curl_getinfo($resource, CURLINFO_EFFECTIVE_URL);
curl_close($resource);

I'm only interested in the $lastUrl address. Is it possible without
wasting bandwidth on downloading the actual trasfer which is at that
address?

Setting RETURNTRANSFER to FALSE outputs transfer directly

Posted by Mikhail Kovalev on August 1, 2008, 5:00 pm
Please log in for more thread options
> Suppose I have something like this
>
> =A0 =A0 $resource =3D curl_init();
> =A0 =A0 curl_setopt($resource, CURLOPT_FOLLOWLOCATION, TRUE);
> =A0 =A0 curl_setopt($resource, CURLOPT_RETURNTRANSFER, TRUE);
> =A0 =A0 curl_setopt($resource, CURLOPT_URL, '......');
> =A0 =A0 curl_exec($resource);
> =A0 =A0 $lastUrl =3D curl_getinfo($resource, CURLINFO_EFFECTIVE_URL);
> =A0 =A0 curl_close($resource);
>
> I'm only interested in the $lastUrl address. Is it possible without
> wasting bandwidth on downloading the actual trasfer which is at that
> address?
>
> Setting RETURNTRANSFER to FALSE outputs transfer directly

Forgot to tell that I'm using CURLOPT_POST & CURLOPT_POSTFIELDS in
there as well

I'm reading about CURLOPT_NOBODY in the manual, but it says
CURLOPT_HTTPGET, CURLOPT_POST and CURLOPT_HTTPPOST will reset
CURLOPT_NOBODY


Posted by Jerry Stuckle on August 1, 2008, 11:24 pm
Please log in for more thread options
Mikhail Kovalev wrote:
> Suppose I have something like this
>
> $resource = curl_init();
> curl_setopt($resource, CURLOPT_FOLLOWLOCATION, TRUE);
> curl_setopt($resource, CURLOPT_RETURNTRANSFER, TRUE);
> curl_setopt($resource, CURLOPT_URL, '......');
> curl_exec($resource);
> $lastUrl = curl_getinfo($resource, CURLINFO_EFFECTIVE_URL);
> curl_close($resource);
>
> I'm only interested in the $lastUrl address. Is it possible without
> wasting bandwidth on downloading the actual trasfer which is at that
> address?
>
> Setting RETURNTRANSFER to FALSE outputs transfer directly

Not really, to get the URL, cURL must download the page, if for no
other reason than to ensure there isn't another redirect.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Posted by Mikhail Kovalev on August 2, 2008, 3:32 am
Please log in for more thread options
> Mikhail Kovalev wrote:
> > Suppose I have something like this
>
> > =A0 =A0 $resource =3D curl_init();
> > =A0 =A0 curl_setopt($resource, CURLOPT_FOLLOWLOCATION, TRUE);
> > =A0 =A0 curl_setopt($resource, CURLOPT_RETURNTRANSFER, TRUE);
> > =A0 =A0 curl_setopt($resource, CURLOPT_URL, '......');
> > =A0 =A0 curl_exec($resource);
> > =A0 =A0 $lastUrl =3D curl_getinfo($resource, CURLINFO_EFFECTIVE_URL);
> > =A0 =A0 curl_close($resource);
>
> > I'm only interested in the $lastUrl address. Is it possible without
> > wasting bandwidth on downloading the actual trasfer which is at that
> > address?
>
> > Setting RETURNTRANSFER to FALSE outputs transfer directly
>
> Not really, =A0to get the URL, cURL must download the page, if for no
> other reason than to ensure there isn't another redirect.

A header is sufficient for this, or am I wrong?
(Which is exactly what CURLOPT_NOBODY does, btw.)

Posted by Jerry Stuckle on August 2, 2008, 9:52 am
Please log in for more thread options
Mikhail Kovalev wrote:
>> Mikhail Kovalev wrote:
>>> Suppose I have something like this
>>> $resource = curl_init();
>>> curl_setopt($resource, CURLOPT_FOLLOWLOCATION, TRUE);
>>> curl_setopt($resource, CURLOPT_RETURNTRANSFER, TRUE);
>>> curl_setopt($resource, CURLOPT_URL, '......');
>>> curl_exec($resource);
>>> $lastUrl = curl_getinfo($resource, CURLINFO_EFFECTIVE_URL);
>>> curl_close($resource);
>>> I'm only interested in the $lastUrl address. Is it possible without
>>> wasting bandwidth on downloading the actual trasfer which is at that
>>> address?
>>> Setting RETURNTRANSFER to FALSE outputs transfer directly
>> Not really, to get the URL, cURL must download the page, if for no
>> other reason than to ensure there isn't another redirect.
>
> A header is sufficient for this, or am I wrong?
> (Which is exactly what CURLOPT_NOBODY does, btw.)

Did you try it? If so, did it work?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Similar ThreadsPosted
curl and download September 14, 2006, 10:27 am
limiting download size with curl February 26, 2008, 11:36 am
cURL question, how to return final URL where Im redirected? July 13, 2007, 7:45 am
Is it possible to list directory content with CURL August 2, 2008, 12:48 pm
Initiate download instead of streaming content February 10, 2008, 10:01 pm
Curl - resume http download - Apache log files. gz October 11, 2005, 3:25 pm
Anyone know how to create automatic download using CURL and creating a new folder every day??? August 7, 2007, 4:26 pm
PluggedOut CMS 0.4.8 Content Management System available for download... March 3, 2005, 3:04 am
PluggedOut CMS 0.4.9 Content Management System available for download... May 12, 2005, 9:16 am
Is HTMLPurifier effective, safe and reliable January 21, 2008, 7:41 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap