在PHP CURL中设置cookie [英] setting a cookie in PHP CURL

查看:83
本文介绍了在PHP CURL中设置cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对php curl概念真的很陌生,谁能给我展示一个简单的示例,说明如何使用 php curl

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 that doesnt work...

$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_exec($ch);
curl_close($ch);

但是当我将它打印成var_dump时,很困惑,请帮忙

but when i take a var_dump of this it gets printed, very confused please help

array (size=1)
  'userid' => string '1:123' (length=8)

如果您感到困惑,请....您可以简单地忽略我上面的编码,让我知道如何使用php curl设置简单的Cookie

推荐答案

我不清楚您希望Cookie发生什么.但是,您可以尝试以下方法:

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);

这篇关于在PHP CURL中设置cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆