Jump to content

Stylw

New Members
  • Posts

    1
  • Joined

  • Last visited

Stylw's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I'm rather new to PHP, and I've run into a problem develeoping this script that I can't figure out. It's fairly simple in that it fetches the user input via a search box and cross references it against a blacklist and whitelist in the form of two seperate .txt. files. However, the enclosed code seems to ignore the second if statement and will always return "unknown website" even if users' input is in the blacklist. The first if statement works correctly though, so I'm a little bit lost as to where I've gone wrong. I'm also not sure how I shoud approach implementing case sensentivity and checking if the user input contains a specfiic word that's on a line. For example, if a user inputted phpfreaks into the search box it would still come out as legimtmate even though I didn't specifically state phpfreaks (it would be the full url, e.g. phpfreaks.com) in the whitelist txt file. From my research I would think the strpos function or preg_match might work, but I'm not sure how I should put it in there. <?php $search = $_POST['search']; $blacklist = file_get_contents("illegitimatesites.txt"); $whitelist = file_get_contents("legitimatesites.txt"); $blacklist = explode("\n", $blacklist); $whitelist = explode("\n", $whitelist); if(in_array($_POST['search'], $whitelist)){ //checks if site is in array echo "This website is an authorised distributor"; } else{ if(in_array($_POST['search'], $blacklist)){ //checks if site is in array echo "This website is NOT an authorised distributor"; } else{ echo "Unknown website"; } } ?>
×
×
  • 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.