You are here: Re: CURL and PHP Redirect « PHP Programming Language « IT news, forums, messages
Re: CURL and PHP Redirect

Posted by R. Rajesh Jeba Anbiah on 09/29/90 11:42

niftyhawk@gmail.com wrote:
> Hi All,
>
> I have a small curl function which spits out a bunch of headers.
>
> The CURL Code is:
>
> $url="http://blahblah.com?Logon";
> $ch = curl_init();
> curl_setopt($ch, CURLOPT_URL, $url);
> curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
> curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
> curl_setopt($ch, CURLOPT_REFERER,
> "http://blahblah.com/default.asp?v=");
> curl_setopt($ch, CURLOPT_VERBOSE, 0);
> curl_setopt($ch, CURLOPT_HEADER, 1);
> curl_setopt ($ch, CURLOPT_POST, 1);
> curl_setopt ($ch, CURLOPT_POSTFIELDS,
> "FormId=0&Config=0&RedirectURL=$RedirectURL&Identification=$UserID&Verification=$Password&DB=$DB&RememberLogon=1&UseEnhancedContent=1");
> curl_setopt ($ch, CURLOPT_COOKIEJAR, 'Ocookie.txt');
> $content = curl_exec ($ch); # This returns HTML
> curl_close ($ch);
> print $content;
>
>
> The HTML sspit out by the above code is:
>
> HTTP/1.1 100 Continue Server: Microsoft-IIS/5.1 Date: Fri, 17 Mar 2006
> 00:14:25 GMT X-Powered-By: ASP.NET HTTP/1.1 200 OK Server:
> Microsoft-IIS/5.1 Date: Fri, 17 Mar 2006 00:14:25 GMT X-Powered-By:
> ASP.NET Connection: close Content-Type: text/html Refresh: 0;
> URL=http://blahblah.com/default.asp?v= Set-Cookie: osaa=guest;
> expires=Monday, 16-Mar-2009 00:14:25 GMT; path=/ Set-Cookie:
> osab=guest; expires=Monday, 16-Mar-2009 00:14:25 GMT; path=/
>
> All this is printed along with the existing HTML on which the above
> curl code is written.

IIRC, this is happening as you have used curl_setopt($ch,
CURLOPT_HEADER, 1);. Set it to 0.

> How do I redirect the existing page to the one
> setup in the headers by making sure of passing the whole header
> information which is spit out by the curl code?

CURLOPT_FOLLOWLOCATION should handle that case, IMHO. But, also you
have wide range of options to store and set HTTP headers in libcurl.
If I'm right, you're missing CURLOPT_COOKIEFILE (should be set to the
same file of cookie jar) as it is needed for reading/setting the cookie
headers when sending requests. Make sure the cookie file is readable
and writable.

FWIW, for testing purpose, you may enable verbose log:

$fp_err = fopen('verbose_file.txt', 'ab+');
fwrite($fp_err, date('Y-m-d H:i:s')."\n\n"); //add timestamp to the
verbose log
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_STDERR, $fp_err);

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

 

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

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