cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Re: Object Moved problem on web host provider (works on local machine)

From: Stephen Pynenburg <spynenburg_at_gmail.com>
Date: Thu, 10 Apr 2008 21:22:27 -0400

Apparently, you can't disable it through .htaccess, but you could try
putting this at the top of the script in question:
ini_set('open_basedir', NULL);

Hope it works,
-Stephen

2008/4/10 ryan pal <ryanpal_at_mail.com>:

> No worries. I do have access to .htaccess. Safe_mode is already
> disabled. What additions should be made to override open_basedir?
>
> ----- Original Message -----
> From: "Stephen Pynenburg"
> To: "curl with PHP"
> Subject: Re: Object Moved problem on web host provider (works on local
> machine)
> Date: Thu, 10 Apr 2008 20:00:36 -0400
>
> Right, sorry - I'm used to a pretty IDE where comments show up green.
> Anyway, does your web host allow you to use ini_set, or .htaccess files?
> If so, you could override the safe mode and open_basedir options manually.
>
> -Stephen
>
> 2008/4/10 ryan pal <ryanpal_at_mail.com>:
>
> > Hi Stephen,
> >
> > Thanks for your reply. You'll notice I commented out that function
> > because that is what was causing the problem to begin with. Upon searching
> > various forums, I came across that "curl_redir_exec" function which was to
> > prevent the error I was getting. Unfortunately since this is a web host
> > provider, I will not be able to do anything with the versions, hence why I
> > need a work around.
> >
> > ----- Original Message -----
> > From: "Stephen Pynenburg"
> > To: "curl with PHP"
> > Subject: Re: Object Moved problem on web host provider (works on local
> > machine)
> > Date: Thu, 10 Apr 2008 18:39:00 -0400
> >
> > I noticed that you use the custom function and have
> > CURLOPT_FOLLOWLOCATION set to 1 in your code. Is that what you meant to do?
> >
> > Aside from that, have a look at this forum topic - you may have an
> > issue with versions.
> > http://www.feedforall.com/forum/viewtopic.php?=&p=9825
> >
> > -Stephen
> >
> > 2008/4/10 ryan pal <ryanpal_at_mail.com>:
> >
> > > 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>.co
> > >
> > > m/storage:/usr/local/4admin/apache/vhosts/<mydomain>.com/web_users:/usr/local/4
> > >
> > > admin/apache/lib/php:/usr/local/4admin/apache/php5/lib/php:/usr/local/4admin/ph
> > > pstuff
> > >
> > > 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%2F
> > > 03%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=&C
> > >
> > > KYporig%5Frec%5Fpage=&CKYporig%5Frec%5Fbook=&CKYprec%5Fpage=&CKYprec%5Fbook=&CK
> > >
> > > Yporig%5Fcfn%5Fseq=&CKYporig%5Fcfn%5Fyear=&CKYprec%5Fdate%5Fto=04%2F03%2F2008&C
> > >
> > > KYprec%5Fdate%5Ffrom=04%2F03%2F2008&CKYpconsid%5Famt%5Fto=&CKYpconsid%5Famt%5Ff
> > >
> > > rom=&CKYpsecond%5Fparty%5Ftype=&CKYpfirst%5Fparty%5Ftype=&CKYpquery%5Forder=&CK
> > >
> > > Ypsecond%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://www.mail.com/Product.aspx>
> > > !
> > >
> > > _______________________________________________
> > > 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://www.mail.com/Product.aspx>
> > > !
> > >
> > > _______________________________________________
> > > http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
> > >
> > >
> >
> > _______________________________________________
> > 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://www.mail.com/Product.aspx>
> > !
> >
> > _______________________________________________
> > http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
> >
> >
>
> _______________________________________________
> 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://www.mail.com/Product.aspx>
> !
>
> _______________________________________________
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
>
>

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2008-04-11