You are here: Re: PHP/CURL how to grab redirecting URL « All PHP « IT news, forums, messages
Re: PHP/CURL how to grab redirecting URL

Posted by -Lost on 06/20/06 04:13

Assuming you are using a redirect via the location header, you could try:

<?php
$_ch = curl_init();
$url = 'http://toe/tmp/curl_redirect.php';

/*
// set the URL
// we want the output, we do not want it output
// follow all "Location: " headers
// avoid getting caught in a loop somewhere
*/
curl_setopt($_ch, CURLOPT_URL, $url);
curl_setopt($_ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($_ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($_ch, CURLOPT_MAXREDIRS, 1); // google.com requires 2

/*
// execute the current CURL session/handler
*/
$_ch_output = curl_exec($_ch);

/*
// where are we now? (302)
*/
print curl_getinfo($_ch, CURLINFO_EFFECTIVE_URL);

curl_close($_ch);
?>

In, curl_redirect.php I put:

<?php
header('Location: http://google.com/');
?>

So, you should see:

http://google.com (first redirect from Location: header)

Change CURLOPT_MAXREDIRS to 2 (where I noted) to see the redirect from http://google.com
to http://www.google.com/.

Hope this helps.

-Lost

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация