TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack (1) Thread Tools Search this Thread Display Modes
Old 12-10-2007, 10:27 AM   #1 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Asterix Reverse TinyURLs

php Code:
function tinyurl_reverse($szAddress)
{
    $szAddress = explode('.com/', $szAddress);
    $szAddress = 'http://preview.tinyurl.com/'.$szAddress[1];
    $szDocument = file_get_contents($szAddress);
    preg_match('~redirecturl" href="(.*)">~i', $szDocument, $aMatches);
   
    if(isset($aMatches[1]))
    {
        return $aMatches[1];
    }
   
    return null;
}

echo tinyurl_reverse('http://tinyurl.com/388onbs');

Snazzy
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following 5 Users Say Thank You to Wildhoney For This Useful Post:
deflated (12-29-2007), Gurnk (12-10-2007), Haris (12-10-2007), Village Idiot (12-11-2007), webosb (01-01-2008)
Old 12-10-2007, 10:31 AM   #2 (permalink)
The Frequenter
Prolific Welcomer Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 360
Thanks: 24
Haris is on a distinguished road
Default

Cool, now all we need is a library.
__________________
Necessity is the mother of invention.

My blog
Haris is offline  
Reply With Quote
Old 12-10-2007, 10:45 AM   #3 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

You do have a point I'll have to get onto it this week sometime.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 12-11-2007, 05:16 AM   #4 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Nice! (char limit)
__________________

Village Idiot is offline  
Reply With Quote
Old 12-29-2007, 05:52 AM   1 links from elsewhere to this Post. Click to view. #5 (permalink)
The Wanderer
 
deflated's Avatar
 
Join Date: Dec 2007
Location: 127.0.0.1
Posts: 19
Thanks: 7
deflated is on a distinguished road
Default

Quote:
Originally Posted by Haris View Post
Cool, now all we need is a library.
What sort of a library do you think of? A class with the ability to be extended by further link encryption services? If yes, I could contribute some functions but I'm still wondering about the legality of those decryption functions. There are services prohibiting the development and the usage of those 'tools'.
It's not that much work to develop such a class because they are quite simple. I think we only need one method which we pass the URL.

Last edited by deflated : 07-18-2010 at 01:27 PM.
deflated is offline  
Reply With Quote
Old 09-26-2009, 01:10 PM   #6 (permalink)
That guy
 
cachepl0x's Avatar
 
Join Date: Sep 2009
Location: San Antonio, TX
Posts: 24
Thanks: 0
cachepl0x is on a distinguished road
Default

PHP Code:
<?php

final class Main
{
    protected static 
$result$address null;
    
    protected function 
__construct() {}
    protected function     
__clone() {}
    
    public static function 
Prepare($address)
    {
        
$address  explode('.com/'$address);
        
$address  'http://preview.tinyurl.com/' $address[1];
        
$document file_get_contents($address);
        
        
preg_match ('~redirecturl" href="(.*)">~i'$document$matches);
    
        if (isset(
$matches[1])) return $matches[1];
        
        return 
null;
    }
    
    public static function 
Result($address)
    {
        if (!isset(
            
self::$address)) {
            
self::$address self::Prepare($address);
        }
        echo 
"<a href='" self::$address "'>" self::$address "</a>";
    }
}

?>

<form action="<?php echo $PHP_SELF;?>" method="post">
<input type="text" name="url" />
<input type="submit" />
</form>

<?php Main::Result($_POST['url']); ?>
Just sayin.
cachepl0x is offline  
Reply With Quote
Old 09-26-2009, 01:52 PM   #7 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

I know this is an old topic, but given the recent bump it should be ok to have a quick chat on the subject.

When trying to resolve where TinyURLs are supposed to go, wouldn't it make more sense just to send a HEAD request to the TinyURL and see where it points rather than scraping the service-specific preview page in the hope the HTML reflects what you want and the value there is accurate.

The HEAD request method should also work across a wide number of URL shortening services making your code much easier if you wish/need to handle multiple services.
Salathe is offline  
Reply With Quote
Old 09-26-2009, 09:54 PM   #8 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

I recently made a script that works for all URL shortening services: http://www.evanbot.com/article/url-lengthener/25

It uses cURL to get the redirect headers to find the original URL.
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 09-27-2009, 04:45 PM   #9 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

I'm not sure if you want this comment on your blog.

This script has a great starting direction. For example, if you wanted to give users the visibility of the long url, and still give the short url service the correct traffic you could do something like this.

PHP Code:
<?php

// Grab the link
$url $_POST['url'];

// Now get the destination.
require 'longurl.php';
$send_to longurl::get('http://tinyurl.com/past9o');

// Now print out the link
echo '<a href="' $url '">' $send_to '</a>';

?>
One major problem is users and search engines would see this and most likely think that the site is trying to send users to the wrong page.

You could however do something similar to whitehouse.gov and display a popup whenever the user wants to visit a short URL.

Better yet, when the user click the short url you could have a default setting that changes the <a>'s visible text to that longer URL. (The href="" could change based on the user preference.) This would give users added security and comfort in where they are headed.
__________________
My Site
adamdecaf is offline  
Reply With Quote
Old 09-28-2009, 01:07 AM   #10 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

That's not an issue with the script, but rather an issue with your implementation. Simply make the href attribute the long URL and the link text same as the original link text to avoid confusion. Remember the script only gets the URL, it is up to you implement it correctly.
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 09-28-2009, 01:18 AM   #11 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

Quote:
Originally Posted by ETbyrne View Post
That's not an issue with the script, but rather an issue with your implementation. Simply make the href attribute the long URL and the link text same as the original link text to avoid confusion. Remember the script only gets the URL, it is up to you implement it correctly.
I guess you didn't understand what I was saying. A search engine and advanced user would notice that the <a>.innerHTML is different from the href="", thus they would not click it and vote it lower in results.
__________________
My Site
adamdecaf is offline  
Reply With Quote
Old 09-28-2009, 09:37 PM   #12 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

No I understood you correctly... Maybe a good example would help:

PHP Code:
$long_url longurl::get('http://tinyurl.com/past9o');

echo 
"<a href='$long_url'>link text</a>"
Notice I use the long URL for the href attribute and I do not use the short URL for the link text.
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 09-28-2009, 09:59 PM   #13 (permalink)
The Contributor
 
ioan1k's Avatar
 
Join Date: Mar 2009
Location: US
Posts: 76
Thanks: 0
ioan1k is on a distinguished road
Default

Wouldn't this defeat the purpose of the tinyUrl in the first place,

I could see getting the original link back to parse as you wish, but the user is posting it as that is how they want it displayed ... to get link text you would need to parse the URL and get it from there (unless you have a WYSIWYG) that changes the link text ( this to would defeat the purpose of tinyURL parsing.. )
if the link has a list of parameters that are added to the query string in the HREF attribute they will still be weary of the link, especially if it is not a trusted site .... ?
__________________
My Portfolio - Work - Need freelance Work?
I've been developing 5 years now, and I learn something new everyday
ioan1k is offline  
Reply With Quote
Old 09-28-2009, 11:21 PM   #14 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

Quote:
Originally Posted by ETbyrne View Post
No I understood you correctly... Maybe a good example would help:

PHP Code:
$long_url longurl::get('http://tinyurl.com/past9o');

echo 
"<a href='$long_url'>link text</a>"
Notice I use the long URL for the href attribute and I do not use the short URL for the link text.
I'm talking about showing users the full link but then directing them to the short link. This will give (sadly) most users the confidence of going to a safe link, while giving that short url service the proper hits.

The issue comes into play when search engines and advanced users see what is going on, both when presented with two different links will become paranoid. The advanced user may copy the visible text and paste that in, while the search engine may mark the page as spam/malicious.

My goal was to give all parties involved the best outcome, but in further contemplation I've decided that doing something similar to search.twitter.com would be better. The user should have the option to expand the link (for security), and the search engine should be able to mark the page as safe.
__________________
My Site
adamdecaf is offline  
Reply With Quote
Old 09-29-2009, 05:23 PM   #15 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

If I remember correctly, this topic was about finding where tinyURLs went. That's what my script does. No more, no less.

How useful it is (or isn't) depends on how you use it. A good example of implementation would be say for blog comment posts, where the comment author may provide a link to his/her website. In this case you may want to automatically convert the URL to its full version if given a short URL.
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 07-05-2012, 01:28 AM   #16 (permalink)
The Visitor
 
Join Date: Jul 2012
Posts: 4
Thanks: 0
hebeyl is on a distinguished road
Default

I'll have to get onto it this week sometime.....








__________________________________________
We cease loving ourselves if no one loves us
WOW Gold
hebeyl is offline  
Reply With Quote
Reply


LinkBacks (?)
LinkBack to this Thread: http://www.talkphp.com/script-giveaway/1693-reverse-tinyurls.html
Posted By For Type Date
TalkPHP - Powered by vBulletin Post #5 Refback 12-29-2007 04:20 PM

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 10:39 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design