0

I already succeeded login using curl with this code:

$data = array(
    "usr" => "myusername",
    "pwd" => "mypassword",
    "login" =>"login",
    "form" => "submit"
);

$ch = curl_init("https://mypage/");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //Untuk redirect absensi goblog
curl_setopt($ch, CURLOPT_POST, true); //POST request absensi ngeselin
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>

How to click link inside the page after succees login attempt?

1 Answer 1

1

PHP is a server side language which means there is no "clicking" or GUI(usually) straight from the cli. You will need to parse the results. You can do this with the DOM PHP extension. Use https://www.php.net/manual/en/domdocument.loadhtml.php to load the results into a new DOM object, them iterate through the elements until you find your link. Finally, take the link's href and make another curl request with that cookie jar that you are using in order to keep the session active.

$data = array(
    "usr" => "myusername",
    "pwd" => "mypassword",
    "login" =>"login",
    "form" => "submit"
);

$ch = curl_init("https://mypage/");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //Untuk redirect absensi goblog
curl_setopt($ch, CURLOPT_POST, true); //POST request absensi ngeselin
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);
curl_close($ch);
$doc = new DOMDocument();

$doc->loadHTML($result)

foreach ($doc->childNodes as $item)
               if(!empty($href = $item->getAttribute('href')))
                 {
                       $ch2 = curl_init("https://mypage/my-account");
                       curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, true); 
                       curl_setopt($ch2, CURLOPT_COOKIEJAR, 'cookie.txt');
                       curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
                       //Your click results
                       $accountResults = curl_exec($ch2);
                 }
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.