I need to get the URL of a redirected page in PHP.
Let’s say I have an URL like http://example.com, while I open this, it redirects to http://redirected_url.com. So the input and output of this PHP function must be like this:
- Input:
http://example.com - Output:
http://redirected_url.com
How can I do this?
Edit: I don’t mean redirection. I need the url of redirected page. So I don’t know redirected url, but I need to find it.
It’s hard to tell from the question, but if you’re wanting to tell if a url you’re accessing is trying to redirect you, you can use
get_headers("http://some_url")and check in key[0] of the response if it’s sent you a 301 status code. Or if it has a “location” header like is mentioned above. php docsLike this:
I’ll leave error (and case sensitivity) handling up to you, but that should get you there