communication
 databases
 directories
 file handling
 html and code
 image editing
 image listing
 sessions and co
 string handling
 information
 forms
 apple stuff
 image handling
 array handling
 lixlpixel
php - snippets
google search terms detected and highlighted.
remove highlighting | keep highlighting
make snippet in "string handling" - download "string compare"
 search
php - snippets

Valid CSS!

php webring logo
prev next
random list
join the Ring!

string handling - string compare was created/last modified on Thu 08 Apr 2004 11:41 PM

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

<?
   
   
// 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
       
}
   }
   
   
?>

learn more about some of the PHP functions used in this snippet: count, each, echo, else, explode, file, for, ord, strpos, tan, var

view the GNU general license - view the GNU library license - search on PHPsnippets - see your code like this

 a lixlpixel.com site

PHParadise.com - PHP-classes.org - your site on safari