fsockopen
doesn't do redirects. You are confused with fopen
that does follow redirects in its quest to fetch the resource, when used with the http-wrapper, and gives you a (read-only) handler to the body of the resource. When used with the http-wrapper, the headers encountered on the way are stored in the variable $http_response_header
, which can be processed to see the final URL.
fsockopen
however just opens a stream to a socket, and therefore does not follow redirects. fsockopen
isn't even HTTP aware. It just opens a TCP socket for reading from and writing to.