JSFiddle - React, Tailwind, and code Playground

by Chintan Upadhayay

HTML

<a href="#one" class="hash">One</a> 
<div>
    <p>some text</p>
</div>
<a href="#two" class="hash">Two</a> 
<div>
    <p>some text</p>
</div>
<a href="#three" class="hash">Three</a> 
<div>
    <p>some text</p>
</div>

CSS

div {
    height: 400px;
}

JavaScript

function traceUrl($url, $hops = 0)
    {
        if ($hops == MAX_URL_HOPS)
        {
            throw new Exception('TOO_MANY_HOPS');
        }

        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_NOBODY, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        $r = curl_exec($ch);

        if (preg_match('/Location: (?P<url>.*)/i', $r, $match))
        {
            return traceUrl($match['url'], $hops + 1);
        }

        return rtrim($url);
    }
    
    traceUrl('http://bit.ly/example')