Jump to content

[SOLVED] how to determine domain/url of page


Recommended Posts

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

 

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!

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.