PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Old September 22nd, 2009, 07:27 AM
Erik Lodin Erik Lodin is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 16 Erik Lodin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 19 m 50 sec
Reputation Power: 0
php5 - What's my global (ISP) IP address?

Is there a way to retrieve the server side global IP address?

$_SERVER['REMOTE_ADDR']; returns the global IP on client side.
$_SERVER['HTTP_HOST']; returns the server side domain name.
$_SERVER['SERVER_ADDR']; returns the server side LAN address (local 192.168.0.1).

How do I get the global address?
__________________
I'm me, but I'm trying hard to be better.

Reply With Quote
Old September 22nd, 2009, 09:40 AM
MatthewJ MatthewJ is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: May 2007
Location: Davenport, Iowa
Posts: 1,021 MatthewJ User rank is Lance Corporal (50 - 100 Reputation Level)MatthewJ User rank is Lance Corporal (50 - 100 Reputation Level)MatthewJ User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 6 Days 12 h 13 m 18 sec
Reputation Power: 9
There may be an easier way, but this will work

PHP Code:
<?php
exec
("ping -n 1 -w 1 www.google.com"$output$result);
preg_match("/([0-9]+\.[0-9]+\.[0-9]+.[0-9]+)/"$output[4], $matches);
echo 
"Google's IP is: ".$matches[1];
?>

Reply With Quote
Old September 22nd, 2009, 07:23 PM
IAmALlama IAmALlama is offline
Me
Click here for more information
 
Join Date: Apr 2007
Location: San Diego, CA
Posts: 2,290 IAmALlama User rank is Lance Corporal (50 - 100 Reputation Level)IAmALlama User rank is Lance Corporal (50 - 100 Reputation Level)IAmALlama User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 11 h 28 m 56 sec
Reputation Power: 10
Quote:
$_SERVER['SERVER_ADDR']; returns the server side LAN address (local 192.168.0.1).

If you were accessing the server through an external IP then it will show that external IP. Sounds like you are accessing the server using a local dns or hosts file. another option from using ping would be to also do something like file_get_contents on the website www.whatismyip.com or pretty much any other website that will show your ip. you could then parse out the ip or try to find a site that shows just the ip with nothing else.

Reply With Quote
Old September 23rd, 2009, 01:26 AM
Erik Lodin Erik Lodin is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 16 Erik Lodin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 19 m 50 sec
Reputation Power: 0
Ask DNS...

I guess this information isn't known by PHP (or the Apache server) and you have to make some kind of DNS request. Ok, great!

I'll give it a try using your code MatthewJ. Thanks!

IAmALlama: I am trying to make the web-server get its own global address (by itself). So, yes... it's very local. :-D

Reply With Quote
Old September 23rd, 2009, 03:27 AM
Erik Lodin Erik Lodin is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 16 Erik Lodin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 19 m 50 sec
Reputation Power: 0
Ok... The code didn't quite work.
My installation (Linux distribution) didn't understand the "-n"-option and returned "Invalid argument".

I modified the code and came up with this functional piece of php:
PHP Code:
 exec("ping -w 1 www.google.com"$output$result);
preg_match("/([0-9]+\.[0-9]+\.[0-9]+.[0-9]+)/"$output[0], $matches);
$ipServer=$matches[1]; 

Works like a charm. Thanks again!

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > php5 - What's my global (ISP) IP address?


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap