Log in and see if page is online with Curl

Asked

Viewed 363 times

0

I wish to log in to different pages with Curl and make sure everything’s okay. Example: login done successfully returns me a text the "login ok" screen if it didn’t work takes some element of the error page and prints me on the screen below the "login error" panel (I will use to test proxys and create chat bots further forward). As an example I tried to make a simple code on Facebook, follows below:

<?php

$login_email = '[email protected]';
$login_pass = 'minhasenha';


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://m.facebook.com/login.php');
curl_setopt($ch, CURLOPT_POSTFIELDS,'charset_test=€,´,€,´,水,Д,Є&email='.urlencode($login_email).'&pass='.urlencode($login_pass).'&login=Login');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$fbMain = curl_exec($ch)
?>

The problem is that after this simple login system do not know how to print down the status that tells me whether the login was successfully done or not, example of what I want to do more with Proxy list tester:

192.173.0.1 Live
192.168.0.2 die
192.168.0.4 Live

1 answer

1


The function curl_exec returns the HTML of the request, and you can also get http code with the function curl_getinfo.

$document = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

With the return of HTML to identify certain strings that identify whether it was logged in or not. I usually use a strpos in such cases.

In your case, you can give a echo $fbMain; and see what returns.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.