Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP cUrl和cookie GX_会话_ID_Php_Curl_Cookies_Genexus - Fatal编程技术网

PHP cUrl和cookie GX_会话_ID

PHP cUrl和cookie GX_会话_ID,php,curl,cookies,genexus,Php,Curl,Cookies,Genexus,我被这件事缠住了 我正在尝试在网站表单中自动执行查询,并使用PHP处理返回响应。我的代码实际上可以工作,但只有在添加以下标题时才能工作: $headers = [ 'Cookie: GX_SESSION_ID=zWfdnmlQgtodK0ax97epfsbma9J0tvVI%2B%2BelShsOIZo%3D; JSESSIONID=E1378A4864FFF03AF4B8BAA0CBB88D89;', ]; curl_setopt($cURLConnection, CURLOPT_HT

我被这件事缠住了

我正在尝试在网站表单中自动执行查询,并使用PHP处理返回响应。我的代码实际上可以工作,但只有在添加以下标题时才能工作:

$headers = [
    'Cookie: GX_SESSION_ID=zWfdnmlQgtodK0ax97epfsbma9J0tvVI%2B%2BelShsOIZo%3D; JSESSIONID=E1378A4864FFF03AF4B8BAA0CBB88D89;',
];
curl_setopt($cURLConnection, CURLOPT_HTTPHEADER, $headers);
JSESSIONIDvar不是问题,没有它脚本运行良好。但是,如果我没有使用有效的GX会话ID(我从谷歌浏览器浏览网站时获取)声明GX会话IDvar,脚本将无法工作

当我用谷歌浏览器浏览网站时,只要我进入网站。cookie在请求头中发送

我不明白这个变量是如何创建的

你能帮我把这个重新创建到我的cURL PHP代码中吗?创建calid GX_会话_ID而无需从浏览器手动获取


谢谢大家

使用curl获取cookie变量作为数组:

$ch = curl_init('http://www.google.com/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// get headers too with this line
curl_setopt($ch, CURLOPT_HEADER, 1);
$result = curl_exec($ch);
// get cookie
// multi-cookie variant contributed by @Combuster in comments
preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $result, $matches);
$cookies = array();
foreach($matches[1] as $item) {
    parse_str($item, $cookie);
    $cookies = array_merge($cookies, $cookie);
}
var_dump($cookies);