phptinyurl

URL shortend not working


I'm using tinyurl for making url's short.

If I create it via site it's working. But when i created via api it's not working.

If mu url have # it's not working other wise it's fine.

Eg: http://example.com/web/#/details/12/23

My code:

$ch = curl_init();  
$timeout = 5;  
curl_setopt($ch,CURLOPT_URL,"http://tinyurl/api-create.php?url=".$url);  
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);  
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);  
$data = curl_exec($ch);  
curl_close($ch);  
return $data;  

Solution

  • Please check the URL in your CURL. If you notice, you have http://tinyurl/ This should be tinyurl(dot)com.

    Upon adding .com, I was able to receive a tiny url in my web browser and also in PHP using your code.

    However, upon adding the below, I now see that maybe stackoverflow is responsible for this (however it is still worth noting just in case)

    Also, I would encourage you to urlencode. This will encode the URL so that it is friendly and should solve any other potential problems.

    curl_setopt($ch,CURLOPT_URL,"http://tinyurl(dot)com/api-create.php?url=".urlencode($url));