Safe to rely CURLINFO_EFFECTIVE_URL instead of Location address?

364 Views Asked by At

When recursively expanding an URL, is it safe to rely on the URL result using curl_getinfo($ch, CURLINFO_EFFECTIVE_URL) other than the Location header (301/302 redirection)?

I found that the location URL might be relative, but the CURLINFO_EFFECTIVE_URL is always absolute. Which one is better? I'm doing recursive expanding for a URL.

Thanks!

1

There are 1 best solutions below

1
Marcin Orlowski On

Using CURLINFO_EFFECTIVE_URL saves you some work as in the end you need to have FQDN anyway:

Location = URI-reference

The field value consists of a single URI-reference. When it has the form of a relative reference ([RFC3986], Section 4.2), the final value is computed by resolving it against the effective request URI ([RFC3986], Section 5).

https://www.rfc-editor.org/rfc/rfc7231