Page 1 of 1

PHP Curl

Posted: Thu Apr 22, 2010 7:19 pm
by n8lieby
Heya,

I've got the following code that is posting to a third party billing site. The problem is that it should be following through to the site's hosted page. Unfortunately, this code is simply barfing the contents of that page back into my site's calling page, rather than merrily forwarding off to the third party. I read that this is commonly due to php being in safe mode or having a locked root, but that’s not the case here, as both of those are disabled when I check phpinfo(). I've got to go through the proxy in order to get out. Could that be what's stopping things? There are no errors in the agent if I check it after the call. Am I missing something obvious?

Code: Select all

                $url = "https://bleh.com/orderform.jsp?";
                $param_string = build_param_string($param);
                $agent = curl_init($url);
                curl_setopt($agent, CURLOPT_PROXY,$proxy_addr);
                curl_setopt($agent, CURLOPT_URL, $url);
                curl_setopt($agent, CURLOPT_HEADER, 0);
                curl_setopt($agent, CURLOPT_POST, count($param));
                curl_setopt($agent, CURLOPT_POSTFIELDS, $param_string);
                curl_setopt($agent, CURLOPT_FOLLOWLOCATION, 1);
                curl_exec($agent);
If I call this from http://mysite.com to https://othersite.com/posttome.jsp, I should end up at https://othersite.com/posttome.jsp, right?

thanks,

-nate

Re: PHP Curl

Posted: Thu Apr 22, 2010 7:53 pm
by John Cartwright
n8lieby wrote:Unfortunately, this code is simply barfing the contents of that page back into my site's calling page, rather than merrily forwarding off to the third party.
cURL will perform the request from the server, not the client. Therefore, it is to be expected that either the content will output or return the content as a variable, but never will perform the request on behalf the client.

Re: PHP Curl

Posted: Fri Apr 23, 2010 4:04 pm
by n8lieby
So is there any option to do this from the client?

thanks,

-nate

Re: PHP Curl

Posted: Fri Apr 23, 2010 4:09 pm
by n8lieby
I found this from here:http://netevil.org/blog/2006/nov/http-p ... thout-curl

But it doesn't allow for prox setting like cURL, which is a blocker.

Code: Select all

  
function do_post_request($url, $data, $optional_headers = null)
  {
     $params = array('http' => array(
                  'method' => 'POST',
                  'content' => $data
               ));
     if ($optional_headers !== null) {
        $params['http']['header'] = $optional_headers;
     }
     $ctx = stream_context_create($params);
     $fp = @fopen($url, 'rb', false, $ctx);
     if (!$fp) {
        throw new Exception("Problem with $url, $php_errormsg");
     }
     $response = @stream_get_contents($fp);
     if ($response === false) {
        throw new Exception("Problem reading data from $url, $php_errormsg");
     }
     return $response;
  }

Re: PHP Curl

Posted: Fri Apr 23, 2010 5:27 pm
by John Cartwright
n8lieby wrote:So is there any option to do this from the client?

thanks,

-nate
PHP is a server side language. If you want to control the client side aspect, you need to use client side languages, such as javascript.