I have a form that gets spammed by random junk so im adding captca however most of my people are not that smart or foreign. So not really good option my alt is to use this a php script to use a xtttp request to check which country they are from but block all but US and CA now one option I have is geoip however that requires me to upload a database every 30days. so I want to turn this JavaScript into a php script that is run when the user visits the page where the loc is saved as a global variable that i can use in the php mailer script but the spammer cant see in the background.(yes if they get smart and use a US proxy it will not work)
here is the site that pulls the country code
https://www.cloudflare.com/cdn-cgi/trace
as you can see the only var i need to save to is loc=US
fl=573f158
h=www.cloudflare.com
ip=
ts=
visit_scheme=https
uag=Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0
colo=IAD
sliver=none
http=http/2
loc=US
tls=TLSv1.3
sni=plaintext
warp=off
gateway=off
rbi=off
kex=X25519
here is the JavaScript that I can use to display on my page and that the spammer can see
<html>
<head>
<script type="text/javascript">
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var country_code = this.responseText.replace(/(\r\n|\n|\r)/gm,"").split('loc=');
document.getElementById("countrycode-container").innerHTML = country_code;
}
};
//OPEN HTTP Request
xhttp.open("GET", "https://www.cloudflare.com/cdn-cgi/trace", true);
xhttp.send();
</script>
</head>
<body>
<br><br><br>
<div id="countrycode-container"></div>
<br><br><br>
</body>
</html>
I would like the submit button when submitted to check the value of country_code and do somin like this
if (isset($_POST['submit'])){
//when user hits submit button and not from US,CA send to spam2
if ($country_code != US,CA) {
place spam2 mailer script here
die();
} else {
continue the mailer script
}
doing this I should be able to eliminate 90% of the spam and not add capcha and I will send the mail to a spam address I have so I can review them and make sure they are legit spam but not affect employees from getting these spam email.
if ($country_code != 'US' && $country_code != 'CA')