Parm Dhillon
Parm Dhillon

Reputation: 65

How to get last redirected url in php

I had used this code to get redirected url in $last_url string :

<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "www.djgol.com/files/download/id/163799"); 
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
$last_url= curl_getinfo($ch,CURLINFO_EFFECTIVE_URL);

$output = curl_exec($ch); 
echo $last_url;
curl_close($ch); 


?>

but i am unable to get redirected url ,, please help me

Upvotes: 0

Views: 1487

Answers (2)

Vignesh
Vignesh

Reputation: 1063

use $_SERVER['HTTP_REFERER']; to get last url. I use this only.

Upvotes: 0

user3477804
user3477804

Reputation:

You're trying to get the URL before starting the request. Try moving the $last_url= curl_getinfo($ch,CURLINFO_EFFECTIVE_URL); line to after the curl_exec($ch); call.

Upvotes: 1

Related Questions