PHP Post data using cURL

In this article am going to explain you how to make HTTP POST using PHP cURL. Some places you may need to post data to remote server where the data will insert to database or process and send you the response. Mostly APIs will use these methods. Apart from API we require it to post the data to remote server from local or for cross domain request.

PHP tutorial to post data using cURL

User will make a conventional form submission and we need to get those values and create an cURL request. In this method we send a set of (array) data and remote script will insert to database (MYSQL Insert) or some other data process.

Download

PHP cURL Post

Now we are going to call the set of php cURL function to post data,

//Initialize cURL 
$ch = curl_init();

//Set location to post data using cURL
curl_setopt($ch, CURLOPT_URL,"http://www.your-website.com/yourScript.php");

//Enable POST method
curl_setopt($ch, CURLOPT_POST, 1);

//Create a array of data
curl_setopt($ch, CURLOPT_POSTFIELDS,
	array(
		'name'=>'your name',
		'email'=>'your email',
		'mobile'=>'your mobile',
		'dob'=>'your date of birth',
		'location'=>'your location'
		));
//Set return True
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//Execute the cURL
echo $server_output = curl_exec ($ch);

//Close
curl_close ($ch);

The above script sends a post a HTTP post request to the given URL with the array of data. Remote script will receive this data and insert into database or process this according to the requirement. Hope you like this article. Thank you.

35 Comments PHP Post data using cURL

  1. Anonymous

    Right now it appears like WordPress is the top blogging platform out there right now. (from what I’ve read) Is that what you are using on your blog?

    Reply
  2. Anonymous

    Very good blog you have here but I was curious if you knew of any user discussion forums that cover the same topics discussed here? I’d really like to be a part of community where I can get feedback from other experienced individuals that share the same interest. If you have any suggestions, please let me know. Cheers!

    Reply
  3. Anonymous

    I am really enjoying the theme/design of your blog. Do you ever run into any browser compatibility problems? A number of my blog visitors have complained about my blog not operating correctly in Explorer but looks great in Firefox. Do you have any ideas to help fix this issue?

    Reply
    1. Prasad G K

      It’s hard to explain with out knowing your blog. Because, it’s depending upon numerous things like HTML structure, CSS images etc.,

      Reply
  4. Anonymous

    I’m not that much of a online reader to be honest but your sites really nice, keep it up! I’ll go ahead and bookmark your website to come back later on. Cheers.

    Reply
  5. Anonymous

    Hi there would you mind letting me know which web host you’re working with? I’ve loaded your blog in 3 different web browsers and I must say this blog loads a lot faster then most. Can you suggest a good web hosting provider at a fair price? Thanks, I appreciate it!

    Reply
  6. Anonymous

    Excellent blog! Do you have any hints for aspiring writers? I’m hoping to start my own blog soon but I’m a little lost on everything. Would you advise starting with a free platform like WordPress or go for a paid option? There are so many choices out there that I’m totally overwhelmed .. Any recommendations? Many thanks!

    Reply
  7. Max

    I’m really enjoying the design and layout of your website. It’s a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire out a developer to create your theme? Superb work!

    Reply
  8. Recompensa

    This is a great website, will you be involved in doing an interview about just how you created it? If so e-mail me!

    Reply
  9. Kbrcehs

    Good day! This is my first comment here so I just wanted to give a quick shout out and say I really enjoy reading through your posts. Thank you!

    Reply
  10. Chaud New

    Have you ever considered about including a little bit more than just your articles? I mean, what you say is important and all. But think of if you added some great pictures or video clips to give your posts more, “pop”! Your content is excellent but with images and videos, this site could definitely be one of the best in its field. Amazing blog!

    Reply
  11. Hgronirgv

    I’m truly enjoying the design and layout of your website. It’s a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire out a developer to create your theme? Superb work!

    Reply
  12. Impresionante

    Does your blog have a contact page? I’m having problems locating it but, I’d like to send you an email. I’ve got some recommendations for your blog you might be interested in hearing. Either way, great website and I look forward to seeing it grow over time.

    Reply
  13. Anonymous

    Hey there! I know this is somewhat off topic but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform as yours and I’m having trouble finding one? Thanks a lot!

    Reply
  14. nkkfos

    Hello! I could have sworn I’ve been to this site before but after browsing through some of the post I realized it’s new to me. Anyways, I’m definitely happy I found it and I’ll be bookmarking and checking back frequently!

    Reply
  15. Anonymous

    When I originally commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get four emails with the same comment. Is there any way you can remove people from that service? Thanks a lot!

    Reply
  16. Mmkbabua

    Hi terrific website! Does running a blog such as this take a large amount of work? I’ve absolutely no knowledge of coding but I had been hoping to start my own blog in the near future. Anyways, if you have any recommendations or tips for new blog owners please share. I understand this is off subject but I just had to ask. Appreciate it!

    Reply
    1. Prasad G K

      Sure. Am getting numerous request similar to this. Will try to put my thought as an article soon. Thanks!

      Reply
  17. Anonymous

    Hello there I am so happy I found your blog, I really found you by error, while I was researching on Askjeeve for something else, Anyhow I am here now and would just like to say kudos for a remarkable post and a all round interesting blog (I also love the theme/design), I don’t have time to browse it all at the minute but I have book-marked it and also added in your RSS feeds, so when I have time I will be back to read a lot more, Please do keep up the awesome work.

    Reply
  18. Toms

    Good post but I was wondering if you could write a little more on this subject? I’d be very grateful if you could elaborate a little bit further. Kudos!

    Reply
  19. Anonymous

    Thanks for the marvelous posting! I actually enjoyed reading it, you could be a great author.I will make certain to bookmark your blog and will eventually come back sometime soon. I want to encourage you to continue your great work, have a nice morning!

    Reply
  20. Anonymous

    Thank you, I have been seeking for details about this subject for ages and yours is the best I have found so far.

    Reply
  21. Anonymous

    Hello there! This is my 1st comment here so I just wanted to give a quick shout out and tell you I genuinely enjoy reading your blog posts. Can you recommend any other blogs/websites/forums that deal with the same topics? Thanks!

    Reply
  22. Anonymous

    Thanks for your personal marvelous posting! I seriously enjoyed reading it, you may be a great author.I will ensure that I bookmark your blog and may come back later in life. I want to encourage yourself to continue your great posts, have a nice holiday weekend!

    Reply
  23. Super

    Wow that was strange. I just wrote an very long comment but after I clicked submit my comment didn’t show up. Grrrr… well I’m not writing all that over again. Anyhow, just wanted to say superb blog!

    Reply
  24. Anonymous

    It’s a pity you don’t have a donate button! I’d without a doubt donate to this superb blog! I suppose for now i’ll settle for bookmarking and adding your RSS feed to my Google account. I look forward to brand new updates and will share this site with my Facebook group. Talk soon!

    Reply
  25. Anonymous

    Howdy! Quick question that’s completely off topic. Do you know how to make your site mobile friendly? My web site looks weird when browsing from my iphone. I’m trying to find a template or plugin that might be able to fix this problem. If you have any suggestions, please share. Appreciate it!

    Reply
  26. Venta

    Hey I am so glad I found your webpage, I really found you by error, while I was looking on Yahoo for something else, Regardless I am here now and would just like to say thanks for a marvelous post and a all round entertaining blog (I also love the theme/design), I don’t have time to browse it all at the moment but I have bookmarked it and also added in your RSS feeds, so when I have time I will be back to read much more, Please do keep up the superb work.

    Reply
  27. Super-pas

    First of all I want to say awesome blog! I had a quick question that I’d like to ask if you do not mind. I was interested to find out how you center yourself and clear your mind prior to writing. I have had difficulty clearing my mind in getting my ideas out there. I truly do enjoy writing but it just seems like the first 10 to 15 minutes are lost just trying to figure out how to begin. Any suggestions or tips? Cheers!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>