PHP ile CURL kulanımı - Thekodprogram
PHP ile CURL kulanımı - Thekodprogram

Hi everyone I will talk about usage of CURL in PHP. We can use the CURL to make some requests to other webpages via http.

CURL is a powerful web engine to carry data through the web protocols. It is a system for transferring data between web sites so that it can be logged in the stretched places or clear any api. With CURL, you can do everything from simple http operations to very complex ftp operations. Sending the value with POST or GET is routed very quickly in a very complex way.

Now take a look at how can we use CURL basically :

We need to start CURL before we can do anything about CURL. After we get started, we can do what we want. Curling library curl_init(); Function. We call this function and do our operations. Then we terminate CURL.

The CURL library has some configuration settings. Now let’s take a look at those settings


Now that we have this information, let’s make examples and reinforce the CURL.

In the example above, we created a curl file and made thecodeprogram.com the url where the transaction will be performed. We can do the same process as follows. As a result, it will not be a problem because it is a target.

You can also create and send other configuration settings as above.

There is another way to send data. I have showed it below:


As you can see above, we have sent the values we want to send into the CURL object that we created as an array and made it workable.

Well, we’ve prepared the data we’re going to send, and I’m hearing you say we won’t talk about how to send them. Now let’s look at it.

We run the CURL object that we created with the curl_exec () method and wait for the operations we want. When it completes, it returns us a value of true or false, and we understand whether or not it has been processed according to this value.


It is executed as above and is thrown to the $result variable.

The returned value:

  • If true process is succesfully.
  • Else if false there is error during the process and it failed.

If the result comes from above, the result is the data within the site. For example, a JSON or XML or CSV-style data can be. We read this data and do the operation we want.

After we finish our operation, you can use curl_close(); function.


Now take a look at the posting data with cURL:

To post data, we’ll turn on the post feature in the configuration settings, and we’ll create and send the data we post.


So if you ask if there is a code for any errors, we can check them as follows.

In the above way, we can have the errors checked.

We talked about what is CURL as simple as this and what does the job. PHP is one of my biggest blessings to me. That’s why I recommend you to use it and learn to go deeper.

Thats all in this article.

Keep following me.

Have a nice coding.

Burak Hamdi TUFAN…

LEAVE A REPLY

Please enter your comment!
Please enter your name here