Saturday, 2 March 2019

grab redirected url by using cURL

I am trying to find where I'll be redirected at. So I tried to functions for this, but none of those are working properly.

the links is here. when you try to enter, you will be redirected:

https://lions-mansion.jp/MA141070/

so I tried use cURL,

function redirect1($url) { 
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0);
        curl_setopt($ch, CURLOPT_TIMEOUT, 60);
        $data = curl_exec($ch);
        $data = curl_getinfo($ch,CURLINFO_EFFECTIVE_URL );
        curl_close($ch);

        return $data;
    }

and also this:

function redirect($url) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $result = curl_exec($ch);
        if (preg_match('~Location: (.*)~i', $result, $match)) {
           $location = trim($match[1]);
        }

        return $result;
    }

But I couldn't find the redirected url.



from grab redirected url by using cURL

No comments:

Post a Comment