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
https://forums.phpfreaks.com/topic/46827-help-with-redirection-url/
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?

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];
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.