2017-07-04 6 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); 
?> 

Ich möchte auf eine neue URL umgeleitet werden, nachdem ich mich erfolgreich anmelden Curl-Skript (https://wordpress.com/me). Ich bekomme nichts auf dem Bildschirm, nachdem ich den Code auf einem localhost ausgeführt habe. auch bin ich nicht in der Lage, alles auf dem Browser anzuzeigen, aber die Cookies eingesetzt sind bereits DateiWie Umleiten, nachdem ich mich zu Curl-Skript anmelden

Antwort

0

Wie wäre es, dies zu cookie.txt, oder habe ich die Frage missunderstood ?:

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

Wenn Sie daran interessiert sind, ich bekomme nur Wordpress-Symbol oben links 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); 


?> 

ich dies versucht haben, aber wenn ich den Browser-Tab nachladen: dabei einige Ketten Anfragen mit curl, versuchen, die Antworten auf diese Frage zu untersuchen. Irgendwelche Ideen, wie man das volle wordpress Benutzerprofil im Browser anzeigt?

0

Haben Sie versucht, nur 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; 
} 

Danach können Sie das „$ exec“ Variable, um analysieren, alle Informationen abrufen Sie (statt nur der Grund „Echo“) benötigen.

(Vorsicht, haben Sie zusätzliche Klammern in Ihrem "wenn" und CURLOPT_POST sollte bei 0 statt 1 in der "if" Anweisung gesetzt werden)

Verwandte Themen