PHP Curl - 登录后重定向 [英] PHP Curl - Redirect after login

查看:240
本文介绍了PHP Curl - 登录后重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从网站获取数据。
首先我这样登录:

I wanted to get data from a website with curl. First I login like this:

$userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4"; 

$ch = curl_init("https://192.168.67.10/Appliance/index.jsp"); 

$username="***"; 
$password="***"; 
$submit = "userid=$username&pass=$password&submitted=true&rememberMe=0";

if(!$ch) { 
    die(sprintf("Fehler[%d]: %s", 
        curl_errno($ch), curl_error($ch))); 
} 
curl_setopt($ch, CURLOPT_VERBOSE, 1); 
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); 
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookie.txt");  
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $submit);

$data = curl_exec($ch); 

if(!$data) { 
    die(sprintf("Fehler [%d]: %s", 
        curl_errno($ch), curl_error($ch))); 

} 

curl_close($ch); 

echo $data;

如何访问其他页面?

登录页面: https://192.168.67.10/Appliance/HomePage/index.jsp
我想访问的页面: https ://192.168.67.10/Appliance/SystemsCenter/Encryption/CertificateStore/index.jsp

提前谢谢。

推荐答案

我没有看到你使用 CURLOPT_POST 。所以请添加:

I didn't see you using CURLOPT_POST. So please add this:

curl_setopt($ch, CURLOPT_POST, 1);

此外,使用启用跟随重定向,以便没有石头保持冷静!

Also, use enable follow redirect, so that no stone keep unturned!

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

这篇关于PHP Curl - 登录后重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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