{"id":318,"date":"2015-02-23T15:20:37","date_gmt":"2015-02-23T23:20:37","guid":{"rendered":"http:\/\/shanelabs.com\/blog\/?p=318"},"modified":"2015-02-23T15:20:37","modified_gmt":"2015-02-23T23:20:37","slug":"does-file_get_contents-follow-redirects-by-default","status":"publish","type":"post","link":"https:\/\/shanelabs.com\/blog\/2015\/02\/23\/does-file_get_contents-follow-redirects-by-default\/","title":{"rendered":"Does file_get_contents follow redirects by default?"},"content":{"rendered":"<p>What happens when PHP&#8217;s file_get_contents() function encounters a 301 Redirect header? I thought I could find out by going to the PHP documentation, but I couldn&#8217;t find anything. So instead, I set up a simple test myself.<\/p>\n<p>Just made a simple script that echos file_get_contents() and pointed it to a URL that I know has a 301 redirect. What happened? It followed it.<\/p>\n<p>Now I&#8217;m not sure how many redirects it will follow (most environments have a limit to prevent infinite loops of one 301 redirect back to another), but <strong>by default file_get_contents() DOES follow redirects.<\/strong><\/p>\n<p>Hope that helps anyone else out there that was curious!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What happens when PHP&#8217;s file_get_contents() function encounters a 301 Redirect header? I thought I could find out by going to the PHP documentation, but I couldn&#8217;t find anything. So instead, I set up a simple test myself. Just made a simple script that echos file_get_contents() and pointed it to a URL that I know has [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-318","post","type-post","status-publish","format-standard","hentry","category-software"],"_links":{"self":[{"href":"https:\/\/shanelabs.com\/blog\/wp-json\/wp\/v2\/posts\/318","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/shanelabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shanelabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shanelabs.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/shanelabs.com\/blog\/wp-json\/wp\/v2\/comments?post=318"}],"version-history":[{"count":1,"href":"https:\/\/shanelabs.com\/blog\/wp-json\/wp\/v2\/posts\/318\/revisions"}],"predecessor-version":[{"id":319,"href":"https:\/\/shanelabs.com\/blog\/wp-json\/wp\/v2\/posts\/318\/revisions\/319"}],"wp:attachment":[{"href":"https:\/\/shanelabs.com\/blog\/wp-json\/wp\/v2\/media?parent=318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shanelabs.com\/blog\/wp-json\/wp\/v2\/categories?post=318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shanelabs.com\/blog\/wp-json\/wp\/v2\/tags?post=318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}