Looking For A Fast, Responsive, SEO Optimized & Self Customizable FREE WordPress Theme?

How
Pricing
My Account

How You Can Use cURL Function

Last Updated on July 7, 2020
by Neeraj Agarwal

Blogging has been a great platform to share useful stuffs. Like tips, secrets, marketing and so on. But today let’s have knowledge about some technical stuff cURL. Have you ever heard about it? No? Carry on then.

cURL is a very useful function which helps to transfer data between the servers. The curl and its library act as a bridge between your server and the server whom you want to communicate. You can easily enable curl function into your Wamp server and use its functionality. Let’s know about how to enable cURL?

Steps To Enable cURL Function

  • Go to Wamp Server –> PHP –> Open php.ini file
  • Find php_curl.dll statement in the php.ini file.

  • Uncomment the statement by removing the semicolon and save the file.

uncomment statement

  • Create a new file let say info.php you can give any name to a file you want and write respective statements and save the file into your Wamp server.

info.php page

Check whether the cURL is now enabled or not

Run info.php file and you can easily check whether the cURL is enable or not. As shown in the image given below.

curl function is enabled

Steps to use cURL function

1. Fetch webpage data

You can set connection with any website by giving the URL address as I mention my https://www.inkthemes.com/ website in the image given below and fetch data from the site.

Create curl.php file or you can give any name to a file and write the code given below.

curl function code

Now run the curl.php file. You can see the webpage of the website.

inkthemes webpage

2. Store webpage data into a file

If you want to store the data in any of the file you want. You can see here the somefile.php is the file generated dynamically which stores the data of https://socialtriggers.com/. You can give any name to a file or you can create it also. You can see in the image given below.

curl code for store webpage data into file

Now run the above code stored in curl.php file and then somefile.php file. As you can see in the image given below the somefile stores the data of https://socialtriggers.com/ webpage.

webpage of a website

3. Fetch file data

Create a file let say posttest.php which stores some data shown in the image given below.

 somefile code

You can fetch the data of posttest.php file directly by using the coding given below. Let say it stored in curl.php file

code for fetch file data

Now execute the curl.php file you get the output given below.

output screen

When you set the boolean value false as in the above code then the output gets changed. You can view in the image given below.

8

The output come like this.

output screen

This is because when you set the boolean value false –> CURLOPT_RETURNTRANSFER print the result and then curl_exec( ) executes which gives boolean value. As a result $data assign with a boolean value “1”.

In case if you set boolean value true –> the control moves to curl_exec( ) and first execute this function as a result $data now holds the return value that comes from posttest.php file and overrides the boolean value.

4. Set time to establish connection

You can set the connection time which allows curl to establish connection with the web page within that limit. If the connection does not establish within the set time limit then the sorry message appears on the output screen or the message you want to print. You can use the code given below.

code set connect time

If the connection does not establish within the desired time limit then the message appears on the screen like this.

output screen

Conclusion

I hope you will find this tutorial useful. You can easily follow the above steps in order to enable and use cURL function in your program.

It is not complicated at all. If you need any help let me know I will definitely resolve your queries.

Leave a Reply Cancel reply

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

InkThemes Logo

Customize Your Website With Beautiful Premium WordPress Themes, Templates & Plugins.

One Click Installation With Advanced Functionality & Awesome Support.

For any query contact us at:
  • [email protected]
Products
  • WordPress Themes
  • Email Marketing
  • Subscription Billing
  • Form Builder
  • Email Verification
Terms of Usage
  • Terms and Conditions
  • Privacy Policy
  • InkThemes Branding
  • Affiliate
  • Contact Us
Join Us
  • Follow us on Twitter
  • Be a fan on Facebook
Analytics
heap-logo1
Help and Support
  • Support
  • Documentation
About
  • Who we are?
  • Careers
Links
  • Blog Categories
  • Marketplace Categories

© 2023 InkThemes LLC. All rights reserved.