{"id":677,"date":"2014-08-02T13:30:00","date_gmt":"2014-08-02T11:30:00","guid":{"rendered":"http:\/\/blog.robinglauser.ch\/?p=677"},"modified":"2014-08-06T21:27:44","modified_gmt":"2014-08-06T19:27:44","slug":"check-useragent-for-curl-or-wget","status":"publish","type":"post","link":"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/","title":{"rendered":"Check useragent for curl or wget"},"content":{"rendered":"<p>If you ever wanted to check if your website was accessed via curl or wget and handle those cases differently you&#8217;ve come to the right place.<\/p>\n<p>In PHP this is really simple. Just use the snippet below to check the user agent and you&#8217;re done.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/nahakiole\/843fb9a29292bfcf012b.js\"><\/script><\/p>\n<p>I used this snippet to differentiate a web user from the command line on the site\u00a0<a href=\"http:\/\/ip.robinio.ch\" target=\"_blank\">ip.robinio.ch<\/a>\u00a0where 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.<\/p>\n<p><a href=\"http:\/\/robinglauser.ch\/blog\/wp-content\/uploads\/2014\/08\/Screenshot-2014-08-06-21.26.23.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-717 size-full\" src=\"http:\/\/robinglauser.ch\/blog\/wp-content\/uploads\/2014\/08\/Screenshot-2014-08-06-21.26.23.png\" alt=\"\" width=\"684\" height=\"540\" srcset=\"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2014\/08\/Screenshot-2014-08-06-21.26.23.png 684w, https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2014\/08\/Screenshot-2014-08-06-21.26.23-380x300.png 380w\" sizes=\"auto, (max-width: 684px) 100vw, 684px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\">If you ever wanted to check if your website was accessed via curl or wget and handle those cases differently you&#8217;ve come to the right place. In PHP this is really simple. Just use the snippet below to check the user agent and you&#8217;re done. I used this snippet to differentiate a web user from the command line on the &#8230; <a class=\"read-more\" href=\"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/\">Read More<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[45,5],"tags":[55,57,56,54],"class_list":["post-677","post","type-post","status-publish","format-standard","hentry","category-development","category-fresh","tag-curl","tag-mac","tag-php","tag-wget"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Check useragent for curl or wget - Robin Glauser<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Check useragent for curl or wget - Robin Glauser\" \/>\n<meta property=\"og:description\" content=\"If you ever wanted to check if your website was accessed via curl or wget and handle those cases differently you&#8217;ve come to the right place. In PHP this is really simple. Just use the snippet below to check the user agent and you&#8217;re done. I used this snippet to differentiate a web user from the command line on the ... Read More\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/\" \/>\n<meta property=\"og:site_name\" content=\"Robin Glauser\" \/>\n<meta property=\"article:published_time\" content=\"2014-08-02T11:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-08-06T19:27:44+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/blog.robinglauser.ch\/wp-content\/uploads\/2014\/08\/Screenshot-2014-08-06-21.26.23.png\" \/>\n<meta name=\"author\" content=\"Robin Glauser\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@robinglauser\" \/>\n<meta name=\"twitter:site\" content=\"@robinglauser\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Robin Glauser\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/\"},\"author\":{\"name\":\"Robin Glauser\",\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/#\/schema\/person\/e1a94504a6ff5171fa13670932514b19\"},\"headline\":\"Check useragent for curl or wget\",\"datePublished\":\"2014-08-02T11:30:00+00:00\",\"dateModified\":\"2014-08-06T19:27:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/\"},\"wordCount\":99,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/#\/schema\/person\/e1a94504a6ff5171fa13670932514b19\"},\"image\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/blog.robinglauser.ch\/wp-content\/uploads\/2014\/08\/Screenshot-2014-08-06-21.26.23.png\",\"keywords\":[\"curl\",\"mac\",\"php\",\"wget\"],\"articleSection\":[\"Development\",\"Fresh\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/\",\"url\":\"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/\",\"name\":\"Check useragent for curl or wget - Robin Glauser\",\"isPartOf\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/blog.robinglauser.ch\/wp-content\/uploads\/2014\/08\/Screenshot-2014-08-06-21.26.23.png\",\"datePublished\":\"2014-08-02T11:30:00+00:00\",\"dateModified\":\"2014-08-06T19:27:44+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/#primaryimage\",\"url\":\"http:\/\/blog.robinglauser.ch\/wp-content\/uploads\/2014\/08\/Screenshot-2014-08-06-21.26.23.png\",\"contentUrl\":\"http:\/\/blog.robinglauser.ch\/wp-content\/uploads\/2014\/08\/Screenshot-2014-08-06-21.26.23.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.robinglauser.ch\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Check useragent for curl or wget\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/#website\",\"url\":\"https:\/\/www.robinglauser.ch\/blog\/\",\"name\":\"Robin Glauser\",\"description\":\"My Blog about Development, Design and my random thoughts.\",\"publisher\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/#\/schema\/person\/e1a94504a6ff5171fa13670932514b19\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.robinglauser.ch\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/#\/schema\/person\/e1a94504a6ff5171fa13670932514b19\",\"name\":\"Robin Glauser\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/10\/DSC_1244_small.jpg\",\"url\":\"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/10\/DSC_1244_small.jpg\",\"contentUrl\":\"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/10\/DSC_1244_small.jpg\",\"width\":800,\"height\":530,\"caption\":\"Robin Glauser\"},\"logo\":{\"@id\":\"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/10\/DSC_1244_small.jpg\"},\"description\":\"I'm a web developer.\",\"sameAs\":[\"https:\/\/www.robinglauser.ch\",\"https:\/\/www.instagram.com\/robinglauser\/\",\"https:\/\/x.com\/robinglauser\"],\"url\":\"https:\/\/www.robinglauser.ch\/blog\/author\/robin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Check useragent for curl or wget - Robin Glauser","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/","og_locale":"en_US","og_type":"article","og_title":"Check useragent for curl or wget - Robin Glauser","og_description":"If you ever wanted to check if your website was accessed via curl or wget and handle those cases differently you&#8217;ve come to the right place. In PHP this is really simple. Just use the snippet below to check the user agent and you&#8217;re done. I used this snippet to differentiate a web user from the command line on the ... Read More","og_url":"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/","og_site_name":"Robin Glauser","article_published_time":"2014-08-02T11:30:00+00:00","article_modified_time":"2014-08-06T19:27:44+00:00","og_image":[{"url":"http:\/\/blog.robinglauser.ch\/wp-content\/uploads\/2014\/08\/Screenshot-2014-08-06-21.26.23.png","type":"","width":"","height":""}],"author":"Robin Glauser","twitter_card":"summary_large_image","twitter_creator":"@robinglauser","twitter_site":"@robinglauser","twitter_misc":{"Written by":"Robin Glauser"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/#article","isPartOf":{"@id":"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/"},"author":{"name":"Robin Glauser","@id":"https:\/\/www.robinglauser.ch\/blog\/#\/schema\/person\/e1a94504a6ff5171fa13670932514b19"},"headline":"Check useragent for curl or wget","datePublished":"2014-08-02T11:30:00+00:00","dateModified":"2014-08-06T19:27:44+00:00","mainEntityOfPage":{"@id":"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/"},"wordCount":99,"commentCount":0,"publisher":{"@id":"https:\/\/www.robinglauser.ch\/blog\/#\/schema\/person\/e1a94504a6ff5171fa13670932514b19"},"image":{"@id":"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/#primaryimage"},"thumbnailUrl":"http:\/\/blog.robinglauser.ch\/wp-content\/uploads\/2014\/08\/Screenshot-2014-08-06-21.26.23.png","keywords":["curl","mac","php","wget"],"articleSection":["Development","Fresh"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/","url":"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/","name":"Check useragent for curl or wget - Robin Glauser","isPartOf":{"@id":"https:\/\/www.robinglauser.ch\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/#primaryimage"},"image":{"@id":"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/#primaryimage"},"thumbnailUrl":"http:\/\/blog.robinglauser.ch\/wp-content\/uploads\/2014\/08\/Screenshot-2014-08-06-21.26.23.png","datePublished":"2014-08-02T11:30:00+00:00","dateModified":"2014-08-06T19:27:44+00:00","breadcrumb":{"@id":"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/#primaryimage","url":"http:\/\/blog.robinglauser.ch\/wp-content\/uploads\/2014\/08\/Screenshot-2014-08-06-21.26.23.png","contentUrl":"http:\/\/blog.robinglauser.ch\/wp-content\/uploads\/2014\/08\/Screenshot-2014-08-06-21.26.23.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.robinglauser.ch\/blog\/2014\/08\/02\/check-useragent-for-curl-or-wget\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.robinglauser.ch\/blog\/"},{"@type":"ListItem","position":2,"name":"Check useragent for curl or wget"}]},{"@type":"WebSite","@id":"https:\/\/www.robinglauser.ch\/blog\/#website","url":"https:\/\/www.robinglauser.ch\/blog\/","name":"Robin Glauser","description":"My Blog about Development, Design and my random thoughts.","publisher":{"@id":"https:\/\/www.robinglauser.ch\/blog\/#\/schema\/person\/e1a94504a6ff5171fa13670932514b19"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.robinglauser.ch\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.robinglauser.ch\/blog\/#\/schema\/person\/e1a94504a6ff5171fa13670932514b19","name":"Robin Glauser","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/10\/DSC_1244_small.jpg","url":"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/10\/DSC_1244_small.jpg","contentUrl":"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/10\/DSC_1244_small.jpg","width":800,"height":530,"caption":"Robin Glauser"},"logo":{"@id":"https:\/\/www.robinglauser.ch\/blog\/wp-content\/uploads\/2015\/10\/DSC_1244_small.jpg"},"description":"I'm a web developer.","sameAs":["https:\/\/www.robinglauser.ch","https:\/\/www.instagram.com\/robinglauser\/","https:\/\/x.com\/robinglauser"],"url":"https:\/\/www.robinglauser.ch\/blog\/author\/robin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/posts\/677","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/comments?post=677"}],"version-history":[{"count":3,"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/posts\/677\/revisions"}],"predecessor-version":[{"id":719,"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/posts\/677\/revisions\/719"}],"wp:attachment":[{"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/media?parent=677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/categories?post=677"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.robinglauser.ch\/blog\/wp-json\/wp\/v2\/tags?post=677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}