Is there any way to know through PHP the origin of the visit?
I would like to hide the registration button and show a message if the visitor is not from Spain, since the application would not work.
Something like:
if($pais != "ES"){
echo "<p>No ofrecemos servicio para tu pais.</p>";
else{
echo "<button type='submit'>Enviar</button>";
}
What you can do is check, through the IP, the country of the visitor.
You can use the hostip.info API.
Example code:
Hope this can help you.
All the best.
I found one that worked for me:
In the previous answers, either the website does not work or the service is not very precise. In my case, it places me in Alcobendas, Madrid and that is not the case.
I quite like this other one https://www.geoplugin.net
Making the following call you will be able to obtain the information of an IP in json format: echo file_get_contents('http://www.geoplugin.net/json.gp?ip=IP_ADDRESS');
You have more information in this article: https://academy.leewayweb.com/como-restrictir-el-acceso-a-una-web-segun-el-pais-del-visitante/
According to Pablo Gutierrez 's comment , I edit and update: