 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
12-10-2007, 10:27 AM
|
#1 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
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.
|
|
|
|
The Following 5 Users Say Thank You to Wildhoney For This Useful Post:
|
|
12-10-2007, 10:31 AM
|
#2 (permalink)
|
|
The Frequenter
Join Date: Sep 2007
Posts: 360
Thanks: 24
|
Cool, now all we need is a library. 
__________________
Necessity is the mother of invention.
My blog
|
|
|
|
12-29-2007, 05:52 AM
|
#3 (permalink)
|
|
The Wanderer
Join Date: Dec 2007
Location: 127.0.0.1
Posts: 19
Thanks: 7
|
Quote:
Originally Posted by Haris
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.
|
|
|
|
12-10-2007, 10:45 AM
|
#4 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
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.
|
|
|
12-11-2007, 05:16 AM
|
#5 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
Nice! (char limit)
|
|
|
|
09-26-2009, 01:10 PM
|
#6 (permalink)
|
|
That guy
Join Date: Sep 2009
Location: San Antonio, TX
Posts: 24
Thanks: 0
|
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. 
|
|
|
|
09-26-2009, 01:52 PM
|
#7 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
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.
|
|
|
|
09-26-2009, 09:54 PM
|
#8 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
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.
|
|
|
|
09-27-2009, 04:45 PM
|
#9 (permalink)
|
|
The Addict
Join Date: May 2009
Posts: 287
Thanks: 5
|
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.
|
|
|
|
09-28-2009, 01:07 AM
|
#10 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
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.
|
|
|
|
09-28-2009, 01:18 AM
|
#11 (permalink)
|
|
The Addict
Join Date: May 2009
Posts: 287
Thanks: 5
|
Quote:
Originally Posted by ETbyrne
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.
|
|
|
|
09-28-2009, 09:37 PM
|
#12 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
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.
|
|
|
|
09-28-2009, 11:21 PM
|
#13 (permalink)
|
|
The Addict
Join Date: May 2009
Posts: 287
Thanks: 5
|
Quote:
Originally Posted by ETbyrne
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.
|
|
|
|
09-28-2009, 09:59 PM
|
#14 (permalink)
|
|
The Contributor
Join Date: Mar 2009
Location: US
Posts: 76
Thanks: 0
|
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 .... ?
|
|
|
|
09-29-2009, 05:23 PM
|
#15 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
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.
|
|
|
|
07-05-2012, 01:28 AM
|
#16 (permalink)
|
|
The Visitor
Join Date: Jul 2012
Posts: 4
Thanks: 0
|
I'll have to get onto it this week sometime.....
__________________________________________
We cease loving ourselves if no one loves us
WOW Gold
|
|
|
|
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 |
|
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|