Jump to content

Help with Redirection URL


drbigfresh

Recommended Posts

I need to somehow obtain the final destination url for a redirection url and am having some problems... Can anyone think of a good way to obtain the address for a redirect...

 

For example: This http://tinyurl.com/2rkafa leads to

http://gizmodo.com/gadgets/cellphones/official-apple-words-iphone-release-late-june-251991.php

 

Is there anyway to return the destination URL in a variable?

 

Thanks,

Scott.

Link to comment
Share on other sites

Sorry, I should have been clearer... I am passing a tinyurl to a page as a variable, and I was then hoping to some how return a header or something from the redirect so my code could put the final destination URL into a variable. So the code will be running on my server, and would essentially be able reverse engineer tinyurl and give me the full url.... That make any sense?

Link to comment
Share on other sites

Guest prozente
<?php
error_reporting(E_ALL);

$service_port = getservbyname('www', 'tcp');
$address = gethostbyname('tinyurl.com');

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket < 0) {
   echo "socket_create() failed: reason: " . socket_strerror($socket) . "\n";
}

$result = socket_connect($socket, $address, $service_port);
if ($result < 0) {
   echo "socket_connect() failed.\nReason: ($result) " . socket_strerror($result) . "\n";
}

$in = "GET /2rkafa HTTP/1.0\r\n";
$in .= "Host: tinyurl.com\r\n";
$in .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1\r\n";
$in .= "Accept: text/xml,application/xml,application/xhtml+xml,text/html;text/plain\r\n";
$in .= "Accept-Language: en-us,en\r\n";
$in .= "Accept-Charset: ISO-8859-1,utf-8\r\n";
$in .= "Connection: Close\r\n\r\n";
$out = '';
$data = '';

socket_write($socket, $in, strlen($in));

while ($out = socket_read($socket, 2048)) {
  $data .= $out;
}

socket_close($socket);

preg_match("/Location: (.*)\r\n/", $data, $matches);
echo $matches[1];
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.