Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tony265's avatar

PHP cURL won't write cookie file to disk public directory.

I'm trying to make my cURL Script write a cookie file to disk public directory, but it won't write. Below is my script, I have created a folder in public/cookies to store cookies.

<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://www.example.com/submit.php");

curl_setopt($ch, CURLOPT_COOKIEJAR, "/cookies/untitled.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "/cookies/untitled.txt");

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "postvar1=value1&postvar2=value2&postvar3=value3");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$output = curl_exec ($ch);

curl_close ($ch);

A cookie should be generated.. Out of Laravel in plain PHP it generates. How can I make it write the cookie to the disk?

0 likes
1 reply
tony265's avatar

Nevermind, I got it working, the problem was a simple slash in the cookie path and the directory that was blocked for writing.

Please or to participate in this conversation.