我正在使用php curl尝试登录到使用令牌的表单。我尝试了不同的组合,其中一些来自StackOverflow,但似乎无法正确实现。
到目前为止,这是我的代码:
$html = new simple_html_dom();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.example.de/My-account');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, '');
$response = curl_exec($ch);
$html->load($response);
foreach($html->find('input[name="jtl_token"]') as $content){
$token = $content->value;
}
$credentials = [
'jtl_token' => $token,
'email' => 'my@email.com',
'passwort' => 'password',
'login' => 1
];
curl_setopt($ch, CURLOPT_URL, 'https://www.example.de/My-account');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($credentials));
curl_setopt($ch, CURLOPT_COOKIEFILE, '');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
echo $response;
我正在使用simple_html_dom
类来获取令牌,然后我尝试将其发送到该页面,但是它不起作用,响应是登录之前的页面。
谢谢。