Feb 232015
 

What happens when PHP’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’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 a 301 redirect. What happened? It followed it.

Now I’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 by default file_get_contents() DOES follow redirects.

Hope that helps anyone else out there that was curious!

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)