Jump to content

Can I use PHP to search for a specific word inside a text file?


damienwc

Recommended Posts

Basically what i'm trying to do is when a user inputs login/password information at a login page, I want PHP to search inside verify.txt and if it finds the login/password combination then allows the user to proceed. Is this possible? And if so, which functions would I use to get the job done?

 

Also, how can I save the login name so that it can be passed to/included in a url?

first open the file thats content has to be read.Then u can split the input from the file according to space,this gives u the words in the file.Note that after splitting the content of the file are converted into an array.Now according to the length of the array iterate and compare the values in the array with the one which u want to search for.I hope this helps u.

you'll need to use fopen to open your file

 

check it out here www.php.net/fopen

 

<?php
$handle = fopen("\home\username\verify.txt", "rb");
$contents = '';
while (!feof($handle)) {
  $contents = fread($handle, 8192);
  echo $contents;
}
fclose($handle);
?> 

 

 

you should put your user/password per line

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.