curl-and-php
Re: Object Moved problem on web host provider (works on local machine)
Date: Thu, 10 Apr 2008 12:46:00 -0500
Any takes on this? If I've left out any details please let me know and
I'll provide them. Any info at all is appreciated, I've come to a dead
stop at this point. Thanks,Ryan
----- Original Message -----
From: "ryan pal"
To: curl-and-php_at_cool.haxx.se
Subject: Object Moved problem on web host provider (works on local
machine)
Date: Wed, 9 Apr 2008 13:25:46 -0500
Hello everyone,
I'm pretty new to cURL and I'm trying to get my frist script to
work. I need to extract data from a site which posts to another ASP
page, which then displays it's results on a 3rd asp page. I'm able
to get this to work correctly on my local computer, however, I'm
running into difficulties on my web host. Original problem on my web
host was "Warning: curl_setopt() [function.curl-setopt]:
CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an
open_basedir is set in..." To prevent this, I chose to use a function
found on one of the forums (see script below). Now I don't get this
error anymore, however the page doesn't seem to redirect correctly.
Here are the details, any info would be appreciated. Local Host:
-----------
safe_mode: off
open_basedir: not set
Web Host Info:
---------------
PHP v 5.2.5
safe_mode: off
open_basedir:
/tmp:/usr/local/4admin/apache/vhosts/<mydomain>.com/httpdocs:/usr/local/4admin/apache/vhosts/<mydomain>.com/logs:/usr/local/4admin/apache/vhosts/<mydomain>.com/storage:/usr/local/4admin/apache/vhosts/<mydomain>.com/web_users:/usr/local/4admin/apache/lib/php:/usr/local/4admin/apache/php5/lib/php:/usr/local/4admin/phpstuff
SCRIPT:
------
<?php//function in place of the FOLLOWLOCATION
function curl_redir_exec($ch,$debug="")
{
static $curl_loops = 0;
static $curl_max_loops = 20; if ($curl_loops++ >= $curl_max_loops)
{
$curl_loops = 0;
return FALSE;
}
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
$debbbb = $data;
list($header, $data) = explode("\n\n", $data, 2);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($http_code ==
301 || $http_code == 302) {
$matches = array();
preg_match('/Location:(.*?)\n/', $header, $matches);
$url = @parse_url(trim(array_pop($matches)));
//print_r($url);
if (!$url)
{
//couldn't process the url to redirect to
$curl_loops = 0;
return $data;
}
$last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL));
/* if (!$url['scheme'])
$url['scheme'] = $last_url['scheme'];
if (!$url['host'])
$url['host'] = $last_url['host'];
if (!$url['path'])
$url['path'] = $last_url['path'];*/
$new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] .
($url['query']?'?'.$url['query']:'');
curl_setopt($ch, CURLOPT_URL, $new_url);
// debug('Redirecting to', $new_url); return curl_redir_exec($ch);
} else {
$curl_loops=0;
return $debbbb;
}
}$url = "http://www.miami-dadeclerk.com/public-records/pubvalidate1.asp?";
$ch = curl_init(); //initialize curl handle
curl_setopt($ch, CURLOPT_URL,$url); //set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //allow redirects
curl_redir_exec($ch,$debug="");
curl_setopt($ch, CURLOPT_COOKIEFILE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //return into variable
curl_setopt($ch, CURLOPT_TIMEOUT, 5); //timeout after 6s
curl_setopt($ch, CURLOPT_POST, 1); //set POST method
curl_setopt($ch, CURLOPT_POSTFIELDS,
"pfirst_party=anderson%2C+john&prec_date_from=04%2F03%2F2008&prec_date_to=04%2F03%2F2008&pdoc_type=LIS&submit=Submit");
//add post fields
$result = curl_exec($ch); //run the whole process
curl_close($ch);echo $result;
//echo $num;
?>
OUTPUT:
------
HTTP/1.1 100 Continue Server: Microsoft-IIS/5.0 Date: Wed, 09 Apr
2008 17:49:49 GMT X-Powered-By: ASP.NET HTTP/1.1 302 Object moved
Server: Microsoft-IIS/5.0 Date: Wed, 09 Apr 2008 17:49:50 GMT
X-Powered-By: ASP.NET Location: searchresult.asp?page=1
Content-Length: 144 Content-Type: text/html Expires: Wed, 09 Apr 2008
17:48:49 GMT Set-Cookie:
Rides20=CKYstrQuery=&CKYprange=&CKYpmisc%5Fref=&CKYpblock%5Fno=&CKYpcfn%5Fseq=&CKYpcfn%5Fyear=&CKYpsubdivision%5Fname=&CKYpdoc%5Ftype=LIS&CKYpdoc%5Fdate%5Fto=&CKYpdoc%5Fdate%5Ffrom=&CKYpfolio%5Fnumber=&CKYpplat%5Fpage=&CKYpplat%5Fbook=&CKYporig%5Frec%5Fpage=&CKYporig%5Frec%5Fbook=&CKYprec%5Fpage=&CKYprec%5Fbook=&CKYporig%5Fcfn%5Fseq=&CKYporig%5Fcfn%5Fyear=&CKYprec%5Fdate%5Fto=04%2F03%2F2008&CKYprec%5Fdate%5Ffrom=04%2F03%2F2008&CKYpconsid%5Famt%5Fto=&CKYpconsid%5Famt%5Ffrom=&CKYpsecond%5Fparty%5Ftype=&CKYpfirst%5Fparty%5Ftype=&CKYpquery%5Forder=&CKYpsecond%5Fparty=&CKYpfirst%5Fparty=ANDERSON%2C+JOHN&CKYptownship=&CKYpsection=&CKYplegal%5Fdescription=&CKYprows%5Freturned=412&CKYVisible=1&CKYPremierSearch=False;
path=/public-records Set-Cookie:
ASPSESSIONIDQCRAASBB=FFKPADAAFBNMMHCDEMDBFNDI; path=/ Cache-control:
private
Object Moved
This object may be found here.
-- Want an e-mail address like mine?
Get a free e-mail account today at www.mail.com!
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
-- Want an e-mail address like mine? Get a free e-mail account today at www.mail.com!
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2008-04-10