string handling
|string compare
snippet to check username / password against a text file
compares fields seperated by a pipe "|" to strings sent via POST variables
full source of string compare [ line 1 - 28 ] | download string compare
| 1 | <? |
| 2 | // lets say you have a file where there's on each line something like |
| 3 | // username|password |
| 4 | $data = file('path/to/file.txt'); // read the file |
| 5 | for($x = 0; $x < count($data); $x++) |
| 6 | { |
| 7 | $parts = explode('|',$data[$x]); |
| 8 | $name_check = strpos($parts[0],$_POST['name']); |
| 9 | if($name_check === true) // important are the === |
| 10 | { |
| 11 | $name = 1; |
| 12 | }else{ |
| 13 | $name = 0; |
| 14 | } |
| 15 | $pass_check = strpos($parts[1],$_POST['password']); |
| 16 | if($pass_check === true) // important are the === |
| 17 | { |
| 18 | $pass = 1; |
| 19 | }else{ |
| 20 | $pass = 0; |
| 21 | } |
| 22 | if($name == 1 && $pass == 1) |
| 23 | { |
| 24 | echo 'hello '.$_POST['name']; |
| 25 | // do whatever |
| 26 | } |
| 27 | } |
| 28 | ?> |
38 hits by 15 users in the last 30 minutes.