doulun0651 2018-07-10 14:37
浏览 48

如何在同一个会话中使用Curl php重定向

Hi I am trying to login to website using Curl php , then I need to redirect to other page and the user should be deleted, and this website is using self sign certificate so far I was able to log In but I am not sure what happen after, therefore the scenario is:

  1. Login to url 1 using token, password, name
  2. Redirect to `link2` (`link2` should do an action)

my code look like:

$sslCertificate = PATH to ssl certificate 
$$cookie_file_path = PATH TO TXT FILE
$url = mylogin page 
//login
curl_setopt($ch, CURLOPT_HTTPHEADER, array($Header ifno..etc));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIE, "cookiename=0");
curl_setopt($ch,CURLOPT_SSLCERT , $sslCertificate);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $username , $passwrod,$token); 
curl_exec($ch);
$html = curl_exec($ch);
print_r($html);
curl_close($ch);

Redirect to delete page (I am not sure if its the right way):

$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, $url2todeleteUser );
curl_setopt($ch2, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch2,CURLOPT_COOKIEFILE,$cookie_file_path);
curl_setopt($ch2, CURLOPT_COOKIE, "cookiename=0");
curl_setopt($ch2,CURLOPT_SSLCERT , $sslCertificate);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
$html = curl_exec($ch2);

var_dump($html);
curl_close($ch2);

For login it works, but for redirect to the $url2todeleteUser , I am not getting any response or error and there is no changes

  • I am not sure if I am setting the session in the right way
  • is there some previous experience with the same situation or some clear code with steps and details what I am doing wrong ?
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
    • ¥15 C# datagridview 单元格显示进度及值
    • ¥15 thinkphp6配合social login单点登录问题
    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配