Question

I need to get final URL after fsockopen i means final because host could redirect me - and i need to get URL which is makes on the final stage. Why i need it you can look here Php redirect to url without www if possible

I was trying to find same questions but some of them are using CURL but some servers don`t support it, and i need to rebuild all script for it.

ps Sorry if duplicate

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top