php - How to know whether a web link is redirecting to any other domain or staying at the same domain? -
I am trying to figure out the status of a page whether the page is redirecting to another domain or in the same domain Is living But this is not working for me.
When I open this URL, I redirect to another domain and I want to know whether it stays on rebelmouse.com or opens another domain.
I have tried curl_init () to know the situation, but this gives 200 it does not provide specific HTTP code to identify redirection.
CODE:
function file_get_contents_curl ($ url) {$ ch = curl_init (); Curl_setopt ($ CH, CURLOPT_USERAGENT, "Mozilla / 5.0 (Windows; U; Windows NT 5.0; N-US; RV .: 1.7.12) Gecko / 20050 915 Firefox / 1.0.7"); Curl_setopt ($ ch, CURLOPT_AUTOREFERER, TRUE); Curl_setopt ($ CH, CURLOPT_HEADER, 0); Curl_setopt ($ CH, CURLOPT_RETURNTRANSFER, 1); Curl_setopt ($ ch, CURLOPT_URL, $ url); Curl_setopt ($ CH, CURLOPT_FOLLOWLOCATION, TRUE); $ Data = curl_xac ($ ch); $ Httpcode = curl_getinfo ($ CH, CURLINFO_HTTP_CODE); $ UrlInfo = curl_getinfo ($ ch, CURLINFO_EFFECTIVE_URL); Curl_close ($ ch); Echo $ urlInfo; $ Return data; }
$ ch = curl_init ('url_here /'); Curl_exec ($ ch); $ Code = curl_getinfo ($ ch, CURLINFO_HTTP_CODE); If (($ code == 301) || ($ code == 302)) {// 301 and 302 redirects specifies. // your stuff} You can find the answer here for more information about
Comments
Post a Comment