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);
?>

i want to be redirected to a new url after i login successfully to curl script (https://wordpress.com/me). am getting nothing on the screen after i run the code on a localhost. also i am not able to view anything on the browser but the cookies are been inserted to cookie.txt file

3 Answers3

0

How about this, or have i missunderstood the question?:

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

If you are interested in doing some chain requests with curl, try investigating the responses on this question: Keeping session alive with Curl and PHP

Anton
  • 1,029
  • 7
  • 19
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);


?>

i have tried this but when i reload the browser tab i get only wordpress icon at the top left . Any ideas on how to display full wordpress user profile on the browser?

Komal12
  • 3,340
  • 4
  • 16
  • 25
0

Did you try to just 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;
}

After that, you can parse the "$exec" variable in order to retrieve any information you need (instead of just the basic "echo").

(watch out, you have extra brackets in your "if" and CURLOPT_POST should be set at 0 instead of 1 in your "if" statement)