dsaba Posted December 27, 2007 Share Posted December 27, 2007 Let's say you have a link that is really a redirect link: http://tinyurl.com/1c2 this redirects to the url: http://www.google.com, but let's say you didn't know this, and wanted to find out. How would you do this, are there any php functions that can help determine the url or domain you are on once you have visited or requested a webpage? ie: with file_get_contents() .... I was thinking parse the html contents for hints, but let's say the mystery url does not have its url anywhere in its source Quote Link to comment https://forums.phpfreaks.com/topic/83340-solved-how-to-determine-domainurl-of-page/ Share on other sites More sharing options...
dsaba Posted December 27, 2007 Author Share Posted December 27, 2007 Without cURL: <?php //array stream_get_meta_data ( resource $stream ) $handle = fopen('http://tinyurl.com/1c2','r'); $arr = stream_get_meta_data($handle); echo '<pre>'; print_r($arr); echo '</pre>'; fclose($handle); ?> outputs: Array ( [wrapper_data] => Array ( [0] => HTTP/1.0 301 Moved Permanently [1] => Connection: close [2] => X-Powered-By: PHP/5.2.5 [3] => Location: http://www.google.com [4] => Content-type: text/html [5] => Content-Length: 0 [6] => Date: Thu, 27 Dec 2007 09:29:55 GMT [7] => Server: TinyURL/1.6 [8] => HTTP/1.0 200 OK [9] => Cache-Control: private [10] => Content-Type: text/html; charset=ISO-8859-1 [11] => Set-Cookie: PREF=ID=30a5c20cb660a019:TM=1198747795:LM=1198747795:S=QCizhTzIC7ELfWzk; expires=Sat, 26-Dec-2009 09:29:55 GMT; path=/; domain=.google.com [12] => Server: gws [13] => Date: Thu, 27 Dec 2007 09:29:55 GMT [14] => Connection: Close ) [wrapper_type] => http [stream_type] => tcp_socket [mode] => r+ [unread_bytes] => 1121 [seekable] => [uri] => http://tinyurl.com/1c2 [timed_out] => [blocked] => 1 [eof] => ) http://us2.php.net/manual/en/function.stream-get-meta-data.php Bingo! thanks dsaba! dsaba: no problem! Quote Link to comment https://forums.phpfreaks.com/topic/83340-solved-how-to-determine-domainurl-of-page/#findComment-423985 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.