Check useragent for curl or wget

Posted on

If you ever wanted to check if your website was accessed via curl or wget and handle those cases differently you’ve come to the right place.

In PHP this is really simple. Just use the snippet below to check the user agent and you’re done.

I used this snippet to differentiate a web user from the command line on the site where you can get your ip address. If the site is accessed via command line only the ip address will be shown without any unnecessary html.


Leave a Reply