Last active
June 25, 2016 14:24
-
-
Save djade007/9eda80ad4567e337b7ac4a09e28e0623 to your computer and use it in GitHub Desktop.
Program to validate Nairaland credentials
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Program to validate login details from nairaland.com | |
* Author djade <www.djade.net> | |
* */ | |
// returns true if successful | |
function validateNL($username, $password) { | |
$link = 'http://www.nairaland.com/do_login'; | |
$data = array('name' => $username, 'password' => $password); | |
$options = array( | |
'http' => array( | |
'header' => "Content-type: application/x-www-form-urlencoded\r\n" | |
. "User-Agent: User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) Gecko/20100101 Firefox/28.0\r\n", | |
'method' => 'POST', | |
'content' => http_build_query($data) | |
) | |
); | |
$context = stream_context_create($options); | |
$result = file_get_contents($link, false, $context); | |
if ($result === FALSE) { | |
echo 'an error occurred'; | |
return false; | |
} | |
// if wrong username is present. That means login failed | |
if(strpos($result, 'Wrong Username or Password') === false) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
if(validateNL('Your Username', 'Your Password')) { | |
echo 'Login successful'; | |
} else { | |
echo 'Login failed'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment