drbigfresh Posted April 13, 2007 Share Posted April 13, 2007 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. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 13, 2007 Share Posted April 13, 2007 um, are you running this script on which page? look at the $_GOLABAL array ( i think its called that), it storea info about the server, client, and page etc. Quote Link to comment Share on other sites More sharing options...
drbigfresh Posted April 13, 2007 Author Share Posted April 13, 2007 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? Quote Link to comment Share on other sites More sharing options...
Guest prozente Posted April 13, 2007 Share Posted April 13, 2007 <?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]; ?> Quote Link to comment Share on other sites More sharing options...
drbigfresh Posted April 13, 2007 Author Share Posted April 13, 2007 Thanks! It worked like a charm. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.