Echo Hyperlink with IP address to go to external webpage

hey you guys, I have this code from many months ago:

        echo '<tr>';
        $index = 0;
        foreach ($row as $key => $col) {
            if ($index === 0) { echo "<td><a href='https://whatismyipaddress.com/ip-lookup' target='_blank'>$col<a/></td>"; }
            else { echo "<td>$col</td>"; }
            $index++;
        }
    		echo '</tr>';

what I would like to do is sort out my superglobals so I can extract the actual IP and let the user click the link and send them to a page like this: https://whatismyipaddress.com/ip/173.28.215.223

I can surely get the data I want from the server var, but the issue is, I don’t think there is one to do what I want, is there? what I’ve noticed is that, depending on the requesting computer, the data can be in all sorts of formats. here is what I’m current capturing with:

gethostbyaddr($_SERVER['REMOTE_ADDR']);

thanks!

what are “all sorts of formats”? it should be only IPv4 or IPv6

they can be in many forms. some of them are like these:

c-24-4-217-222.hsd1.ca.comcast.net
fwdproxy-ftw-001.fbxx.net
111-21-16-235.client.mchsi.com
crawl-66-249-75-147.googlebot.com
h222.71.131.40.static.ip.windstream.net
mail.church.org

so what I’m trying to do is extract the IP address, in the appropriate format, from those which ARE possible. obviously the last one of those above examples would not be possible, as it’s just an email server’s name. I think this is an easy issue, and maybe I just need a string function and the server var’s return value? I may have just solved my own problem. But can you tell me if you know what I mean here? thanks.

still don’t get what you want. why don’t you just take $_SERVER[‘REMOTE_ADDR’]?

yeah I don’t think we’re on the same page, chorn. that’s OK. I’ve found a workaround. so thanks for getting back to me. I’ll consider this thread closed.

Sponsor our Newsletter | Privacy Policy | Terms of Service