setting a cookie in PHP CURL

前端 未结 3 1919
陌清茗
陌清茗 2020-12-21 01:36

Im really new to the php curl concept, can anybody show me a simple example of how to set a cookie in the browser using php curl

this is my code tha

3条回答
  •  半阙折子戏
    2020-12-21 02:10

    I'm not clear on what you are expecting to have happen with cookies. However, you might try this:

    $ch = curl_init('http://localhost/setc.php?userid=123&panelid=1');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // get headers too with this line
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookies.txt');
    curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookies.txt');
    curl_setopt($ch, CURLOPT_COOKIE, 'cookiename=cookievalue');
    curl_exec($ch);
    curl_close($ch);
    

提交回复
热议问题