I’ve got a website set up, which essentially performs certain checks on a user and then redirects them. One of these checks is a simple country check.
To slightly reduce my reliance on user input for the country codes, I’m using http://textextjs.com. I’m using a “tag” input to record the countries the project is allowed to be accessed from.
// Country check $ allowedCountries = array('GB', 'US', 'SE', 'IN'); $ countryCode = $ _SERVER["HTTP_CF_IPCOUNTRY"]); if(!in_array($ countryCode, $ allowedCountries)) { // redirect to error.php?country }
I’m not sure how a professional developer would store the data. The closest topic I could find is: https://stackoverflow.com/questions/145185/best-way-to-store-tags-in-a-sql-server-table – however I am a hobbyist coder at best and the accepted answer doesn’t make sense to me.
I’ve currently got it working by storing the countries as a string in the same table as the project, and doing some messy stuff with explosions but this doesn’t feel like the way a real developer would do it.