Hello, I've been having some troubles with this function lately.
I'm trying to validate if certain user account exists [from a database outside my website] before proceeding with the script, so in order to do that I'm using the following code:
$account = 'test';
$password = '1234';
$data = array('username' => $account, 'password' => $password);
$content = file_get_contents('http://localhost/misc/login.php', false, stream_context_create( array('http' => array('method' => 'POST', 'header' => 'Content-Type: application/x-www-form-urlencoded', 'content' => http_build_query($data) ) ) ) );
$find = 'Welcome '.$account.'';
$search = strpos($content, $find);
if($search === false){
echo 'Incorrect login information. Please try again.';
} else {
echo 'Valid user account';
}
No matter what user account/password combination I use, it always fails, even with a known-functional account.
I did some tests to find out what was wrong, and printed the $_POST values to check they were the right ones. Turns out that only the first field/value is being sent, so on the login page, I get the username, but an empty password, same if I re-arrange $data, with the password as the first array value, I get the password on the login screen but not the username.
Any ideas of whats causing this?
Thanks in advance,
-javier