⊗ppSpCrInr 29 of 83 menu

CURL Library in PHP

The CURL library allows making HTTP requests and receiving the HTML code of website pages into variables. It can work with cookies, HTTP headers, and also allows submitting forms and following redirects.

Basic work with CURL consists of just three functions: curl_init, curl_setopt and curl_exec.

The curl_init function initializes a session of working with the library and stores it in a variable. Further work is done with this variable.

The next stage is settings - they are done using the curl_setopt function, which takes the variable with the session as the first parameter, the name of the setting (as a PHP constant) as the second parameter, and the value of the setting as the third parameter.

After the settings, the curl_exec function is called, which executes the request to the site in accordance with the settings. This function returns the HTML code of the specified page.

Let's look at the minimally required settings (what they do is described in the comments):

<?php // Page address for the request: $url = 'http://test.loc'; // Initialize the session: $curl = curl_init(); // Specify the page address: curl_setopt($curl, CURLOPT_URL, $url); // Execute the request: curl_exec($curl); ?>

Create a site on your local machine test.loc. Access it via CURL.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline