cURL script doens't post

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
puma10
Forum Newbie
Posts: 11
Joined: Thu Aug 18, 2011 2:18 pm

cURL script doens't post

Post 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
Last edited by puma10 on Wed Aug 24, 2011 6:21 pm, edited 1 time in total.
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: cURL script doens't post

Post 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
puma10
Forum Newbie
Posts: 11
Joined: Thu Aug 18, 2011 2:18 pm

Re: cURL script doens't post

Post 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!
phphelpme
Forum Contributor
Posts: 261
Joined: Sun Nov 21, 2010 3:32 pm

Re: cURL script doens't post

Post by phphelpme »

Have you tried running the result instead of outputting it?

Code: Select all

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
Best wishes
puma10
Forum Newbie
Posts: 11
Joined: Thu Aug 18, 2011 2:18 pm

Re: cURL script doens't post

Post 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!
phphelpme
Forum Contributor
Posts: 261
Joined: Sun Nov 21, 2010 3:32 pm

Re: cURL script doens't post

Post 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
Post Reply