⊗ppSpCrCSB 37 of 83 menu

Sending Cookies Back via CURL in PHP

Cookies saved in a file can be automatically sent back on the next request. This is done using two options: the CURLOPT_COOKIEJAR option commands to accept and save cookies to a file, and the CURLOPT_COOKIEFILE option commands to send the saved cookies to the server.

Let's set these options:

<?php $cookieFilePath = $_SERVER['DOCUMENT_ROOT'] . '/cookie.txt'; curl_setopt($curl, CURLOPT_COOKIEFILE, $cookieFilePath); curl_setopt($curl, CURLOPT_COOKIEJAR, $cookieFilePath); ?>

Make two requests to the following page:

<?php if (!empty($_COOKIE)) { echo date('H:i:s', $_COOKIE['time']); } else { setcookie('time', time(), time() + 3600, '/'); echo 'cookie saved'; } ?>

Make sure that on the first request the cookie is saved to the file, and on the second - it is sent back.

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