Tim Habersack

Page 2 of 20

How to get the final url after redirects

Sometimes, you have a link. And you want to save the actual, final url that link points to. A great example of this is trying to archive something on twitter. You’ll want to store final urls for ones that are tweeted, not their url shortened one.

Anyway, I wrote this really quick in PHP and it works!

$d['initial_url'] = 'https://t.co/NOKpf0iHpR';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $d['initial_url']);
curl_setopt($ch, CURLOPT_URL, $d['initial_url']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$d['final_url'] = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);

This outputs:

    [initial_url] => https://t.co/NOKpf0iHpR
    [final_url] => https://tim.hithlonde.com/2016/announcing-js-space/

I just installed Counter-Strike: Source, and I am not sure why. I think it’s because I want to see cs_italy again and hear that music just one more time..

I spent my lunch break filling out my ballot. There are still a couple local measures I need to research more.

Woke up this morning and everyone in my family is sick, including me. Definitely taking a sick day.

The Shining Blade

​Within the stone crypt,

light glinted from shining blade,

defying times curse.

« Older posts Newer posts »

Copyright © 2018 Tim Habersack

Theme by Anders NorenUp ↑