Your better off doing this in a database, easier to index and search. But if you want to search through a text file, you'll need to open the text file for reading, read in the content of the file, then use strrpos() to find the position of the MAC address, or it will return FALSE if its not in there.
You could also do a grep for it, using the system() command in php. That assumes your webhost allows the system command.
hope that helps.
kylegetson
Junior Poster in Training
89 posts since Sep 2009
Reputation Points: 26
Solved Threads: 12
before you write the file (your fwrite statement) but after you open the file for readhing and writing try this:
$filecontents = fread($fp, filesize("MACS.data"));
if(strpos($filecontents,"$dMAC:$dMAC1:$dMAC2:$dMAC3:$dMAC4:$dMAC5") === FALSE){
//store this MAC address, it's unique
}else{
//you already have this one
}
notice the 3 equal signs. that's intentional. strpos() will return 0 (int) if the string your searching for starts at the first position in the string, 2 equal signs like ==false will cause a false positive, because 0==false is true, however 0===false is not.
kylegetson
Junior Poster in Training
89 posts since Sep 2009
Reputation Points: 26
Solved Threads: 12
use header(). Make sure you don't have any output on your savedata.php.
header("Location: getdata.php");
If you need to pass back a message you could use session variables, or pass information on the query string. like getdata.php?error=duplicate+MAC
kylegetson
Junior Poster in Training
89 posts since Sep 2009
Reputation Points: 26
Solved Threads: 12