Skip to content

Instantly share code, notes, and snippets.

@esedic
Created November 20, 2023 23:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esedic/52d35b54366b2e8000877df7c7442656 to your computer and use it in GitHub Desktop.
Save esedic/52d35b54366b2e8000877df7c7442656 to your computer and use it in GitHub Desktop.
Prevent PHP execution if USER_AGENT is bot
<?php
// While not foolproof, you can check the USER_AGENT string and only run that code if 'bot' does not exist.
if(stripos($_SERVER['HTTP_USER_AGENT'],'bot') === false){ }
// This would stop any bot that actually has bot in the user agent string that also does not pay attention to robots.txt.
// Source: https://stackoverflow.com/a/17600047/1090042
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment