2017-07-04 51 views
0
<?php 
$username = ""; 
$password = ""; 
$url = "https://wordpress.com/wp-login.php"; 
$cookie = dirname(__FILE__)."/cookie.txt"; 

$postdata = "log=".$username."&pwd=".$password."&rememberme=forever&wp-submit=Log+In&redirect_to=https%3A%2F%2Fwordpress.com%2F&testcookie=1 
"; 
$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 

curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); 
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie); 
curl_setopt ($ch, CURLOPT_REFERER, "https://wordpress.com/wp-login.php?redirect_to=https%3A%2F%2Fwordpress.com%2F"); 
curl_setopt($ch, CURLOPT_VERBOSE, true); 
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt ($ch, CURLOPT_POST, 1); 

$result = curl_exec ($ch); 
if(!$result) { 
    echo "erro".curl_error($ch); 
} 
if($result) { 


    { 


    curl_setopt($ch, CURLOPT_POST, 1); // change back to GET 
    curl_setopt($ch, CURLOPT_URL, 'https://wordpress.com/me'); // set url for next request 

    $exec = curl_exec($ch); // make request to buy on the same handle with the current login session 
} 
} 
curl_close($ch); 
unset($ch); 
?> 

我想后,我成功登录卷曲脚本(https://wordpress.com/me)将被重定向到一个新的URL。在本地主机上运行代码后,屏幕上什么都没有。还我不能够在浏览器中查看什么,但饼干被插入到cookie.txt文件如何重定向后,我洛卷曲脚本

回答

0

这个怎么样,还是我missunderstood问题?:

header("Location: http://newurl.com"); 
exit(); 

如果您有兴趣做一些连锁的请求,卷曲,试图在这个问题调查的回应:Keeping session alive with Curl and PHP

0
$result = curl_exec ($ch); 
if(!$result) { 
    echo "erro".curl_error($ch); 
} 
if($result) { 
curl_setopt ($ch, CURLOPT_URL, "https://wordpress.com/me"); 
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0"); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); 
echo $resulttwo = curl_exec ($ch); 


if(!$resulttwo) { 
    echo "erro".curl_error($ch); 
} 
    //header("Location: https://wordpress.com/me"); 
//exit(); 
} 
curl_close($ch); 
unset($ch); 


?> 

我已经试过这种但是当我重新加载浏览器选项卡我在左上角只得到WordPress的图标。关于如何在浏览器上显示完整WordPress用户配置文件的任何想法?

0

你试过只是echo $exec;

if($result) { 
    curl_setopt($ch, CURLOPT_POST, 0); // change back to GET 
    curl_setopt($ch, CURLOPT_URL, 'https://wordpress.com/me'); // set url for next request 
    $exec = curl_exec($ch); // make request to buy on the same handle with the current login session 
    echo $exec; 
} 

之后,你可以解析“$ EXEC”变量,以获取你需要(而不是仅仅是基本的“回声”)的任何信息。

(看出来,你有你的“如果”和CURLOPT_POST应在0而不是1在您的“如果”语句设置额外的支架)