Thursday, 13 October 2016

string compare

snippet to check username / password against a text file
compares fields seperated by a pipe "|" to strings sent via POST variables 
<?php




// lets say you have a file where there's on each line something like
// username|password

$data = file('path/to/file.txt'); // read the file

for($x = 0; $x < count($data); $x++)
{
    $parts = explode('|',$data[$x]);
    $name_check = strpos($parts[0],$_POST['name']);
    if($name_check === true) // important are the ===
    {
        $name = 1;
    }else{
        $name = 0;
    }
    $pass_check = strpos($parts[1],$_POST['password']);
    if($pass_check === true) // important are the ===
    {
        $pass = 1;
    }else{
        $pass = 0;
    }
    if($name == 1 && $pass == 1)
    {
        echo 'hello '.$_POST['name'];
        // do whatever
    }
}


?>

0 comments:

Post a Comment