I’m attempting to hobble together some code I’ve found to make a simple search box which cross references inputted text to a text file and returns one of three results accordingly. These results are legitimate, not legitimate and unknown. I’ve managed to successfully do it with two conditions, but once I add in a third I seem to completely fail.
I’m assuming the failure in the script is due to my borked logic in how I’m approaching it. At the moment I have both a whitelist (legitimatesites.txt) and blacklist (illegitimatesites.txt) and I’m attempting to read the blacklist after there is no match in the white list. If the script doesn’t detect text in the blacklist, it’ll throw out an echo with an “unknown site” message.
I haven’t done that successfully yet though, and as soon as I add in the block of code for the blacklist the script will break. I’m really new to programming, so I’m a little bit lost on what I’m doing wrong. Could anyone point me in the direction I’ve screwed up?
In addition to this, is there a better way to go about this whole thing? At the moment I have to add in four entries into each text file for every separate site (e.g. http://example.com, http://www.example.com, example.com, www.example.com). I’m 100% sure you’re probably looking at this in horror, so suggestions on the entire structure are appreciated.
sitechecker.php
[php]$search = $_POST[‘search’];
$text = file_get_contents(‘legitimatesites.txt’);
$lines = explode("\n", $text);
if(in_array($_POST[‘search’], $lines)){ //checks if site is in array
echo “This website is an authorised distributor”;
}elseif{
$search = $_POST[‘search’];
$text = file_get_contents(‘illegitimatesites.txt’);
$lines = explode("\n", $text);
if(in_array($_POST[‘search’], $lines)){ //checks if site is in array
echo “This website is NOT an authorised distributor. It is highly recommended you do not purchase from this site.”;
}
}else{
echo “Information on this website is unknown. Proceed with caution.”;
} ?>[/php]
index.html
[code]
.update { font-family: Georgia; color: #0000FF; } <div id="searchresults">Search results: <span id="results" class="update"></span>
</div>
</div>