Page 1 of 1

cURL script doens't post

Posted: Tue Aug 23, 2011 5:17 pm
by puma10
Hello everyone

I can not get the following script to post. Did I make a mistake somewhere?

Code: Select all

<?php
//
// A very simple PHP example that sends a HTTP POST to a remote site
//
$post_data = array(
        'xnadfjsdp' => '*5tadfafI$',
        'xnQ6adfagp' => '*5t6adsfasgVJI$',
        'xmadfafD' => 'nGtvadfI-26fghgaha2r6PfafR5kYBU',
        'actionType' => 'TGVh4sv',
        'First Name' => 'joe',
        'Last Name' => 'schmoe',
        
);



$ch = curl_init();
// set referer:
curl_setopt($ch, CURLOPT_REFERER, "http://www.google.com/");

// This allows you to type google.com and not http://www.google.com
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );

curl_setopt($ch, CURLOPT_URL,"https://crm.zoho.com/crm/WebToLeadForm");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);

curl_exec ($ch);
curl_close ($ch); 
?>
Cheers and thanks

Re: cURL script doens't post

Posted: Tue Aug 23, 2011 10:12 pm
by twinedev
There are some setting for dealing with connecting to a SSL site (you can tell it to try to not verifying the certificate). I forget what it was offhand, but where I worked before I remember we had to modify scripts to do that.

Not sure if that is your issue, but would be a good place to start.

(Also, are you getting any type of errors?)

-Greg

Re: cURL script doens't post

Posted: Thu Aug 25, 2011 9:00 am
by puma10
twinedev wrote:There are some setting for dealing with connecting to a SSL site (you can tell it to try to not verifying the certificate). I forget what it was offhand, but where I worked before I remember we had to modify scripts to do that.

(Also, are you getting any type of errors?)
I found this in the documentation and added it. It seems that the redirect I put in the array that is processed on their server is working however the data is still not getting posted.

// alllow all ssl certificates
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

Thanks twindev!

Re: cURL script doens't post

Posted: Thu Aug 25, 2011 3:53 pm
by phphelpme
Have you tried running the result instead of outputting it?

Code: Select all

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
Best wishes

Re: cURL script doens't post

Posted: Fri Aug 26, 2011 7:23 pm
by puma10
This looks to finally be the answer. Thank you so so much phphelme! You are genius and I am forever in your debt!

Re: cURL script doens't post

Posted: Sat Aug 27, 2011 2:13 pm
by phphelpme
Glad I could help you out.

Just a quick note on the code that you added:

Code: Select all

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
As long as you trust the site that you are logging onto then that is fine but normally that would be a major security risk as that basically is saying ignore all facts that the security certificate is not verified or recognised and go ahead anyway and connect.

If you are planning on connecting to other sites that you are not sure about then I would suggest you review your script to be more secure and if possible download the certificate by viewing the address in your browser normally and refering to that certificate you have to install when connecting via cURL.

Glad you got it working though.

Best wishes