PHP cURL requests to symfony 1.4 app not possible

I have an old symfony 1.4 application for which I now want to realize a remote login and some action calls via PHP and cURL. The problem is, that the user doesn’t seem to be logged in for the additional action calls and I always get response from the actions (except the login action), that the username and/or password is wrong, which is similar to "not logged in". Both the cURL requests are made from the same domain (for testing) from the same stand alone php script after each other.
Calling both the actions after eacht other with postman works quite fine.

I would appreciate if you could help me. Here’s my code for the login:

$strCookieFilePath = __DIR__."/cookie.txt";

$curlHandle = curl_init();
$strBodyJson = json_encode(array('login_token' => '...'));

$arrOptions = array(
    CURLOPT_URL => '',
    CURLOPT_POSTFIELDS => $strBodyJson,
    CURLOPT_VERBOSE => true,
        'Content-Type: application/json',
        'Content-Length: ' . strlen($strBodyJson)

$strResponse = curl_exec($curlHandle);
echo $response . '<br />';

$strError = null;
if (curl_errno($curlHandle)) {
    echo = curl_error($curlHandle) . '<br />';

Here’s my code for adding data via post cURL request:

$strCookieFilePath2 = __DIR__."/cookie2.txt";
$postinfo = "value1=...&value2=...&value3=...";

$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $strCookieFilePath2);
curl_setopt($ch, CURLOPT_COOKIE, "symfony=".$_COOKIE['symfony']);
curl_setopt($ch, CURLOPT_USERAGENT,
    "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);
$response =  curl_exec($ch);

echo $response.'<br />';

$strError = null;
if (curl_errno($curlHandle)) {
    $strError = curl_error($curlHandle);
    echo $strError . '<br />';

Thanks and kind regards in advance!

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

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