473,396 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Find localhost’s IP number

Hi, I am running apache on local pc/ under Windows.

I need to figure out the ip number of the pc inside PHP. This is the
number available when you do ipconfig, and not the 127.0.0.1!

So the slow way I have figured out is to do a system call to doc,
using `ipconfig`, and then regex the result and figure out the ip.
Is there a fater/more efficient way to do this?

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-Find-loc...ict131475.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=438714
Jul 17 '05 #1
6 2451
>Hi, I am running apache on local pc/ under Windows.

I need to figure out the ip number of the pc inside PHP. This is the
number available when you do ipconfig, and not the 127.0.0.1!
Never assume that a web server has only one IP address. It isn't
that uncommon for a web server to occupy an entire class C. (253
usable addresses or so.)
So the slow way I have figured out is to do a system call to doc,
using `ipconfig`, and then regex the result and figure out the ip.
Is there a fater/more efficient way to do this?


If you want the IP address that the client contacted the server on,
look at $_SERVER['SERVER_ADDR']. This may well vary if the server
has IP-based virtual hosts, and it might end up being 127.0.0.1 if
you accessed it with http://127.0.0.1/foo.php from your browser on
the server itself.

Gordon L. Burditt
Jul 17 '05 #2

"steve" <Us************@dbForumz.com> wrote in message
news:Tv******************@cyclops.nntpserver.com.. .
Hi, I am running apache on local pc/ under Windows.

I need to figure out the ip number of the pc inside PHP. This is the
number available when you do ipconfig, and not the 127.0.0.1!

So the slow way I have figured out is to do a system call to doc,
using `ipconfig`, and then regex the result and figure out the ip.
Is there a fater/more efficient way to do this?

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-Find-loc...ict131475.html Visit Topic URL to contact author (reg. req'd). Report abuse:

http://www.dbForumz.com/eform.php?p=438714

gethostbynamel($dns_name_of_computer).
Jul 17 '05 #3
"Chung Leong" wrote:
"steve" <Us************@dbForumz.com> wrote in message
news:Tv****************@cyclops.nntpserver.com...
Hi, I am running apache on local pc/ under Windows.

I need to figure out the ip number of the pc inside PHP. This is

the
number available when you do ipconfig, and not the 127.0.0.1!

So the slow way I have figured out is to do a system call to doc,
using `ipconfig`, and then regex the result and figure out the

ip.
Is there a fater/more efficient way to do this?

--
http://www.dbForumz.com/ This article was posted by

author’s request
Articles individually checked for conformance to usenet standards
Topic URL:

http://www.dbForumz.com/PHP-Find-loc...ict131475.html
Visit Topic URL to contact author (reg. req’d). Report

abuse:
http://www.dbForumz.com/eform.php?p=438714

gethostbynamel($dns_name_of_computer).


I don’t have DNS on my pc, so I tried
gethostbynamel(’localhost’)
but it returns 127.0.0.1

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-Find-loc...ict131475.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=438855
Jul 17 '05 #4
"steve" wrote:
[quote:5b9ab702e4="Chung Leong"]"steve"
<Us************@dbForumz.com> wrote in message
news:Tv****************@cyclops.nntpserver.com...
Hi, I am running apache on local pc/ under Windows.

I need to figure out the ip number of the pc inside PHP. This is

the
number available when you do ipconfig, and not the 127.0.0.1!

So the slow way I have figured out is to do a system call to doc,
using `ipconfig`, and then regex the result and figure out the

ip.
Is there a fater/more efficient way to do this?

--
http://www.dbForumz.com/ This article was posted by

author’s request
Articles individually checked for conformance to usenet standards
Topic URL:

http://www.dbForumz.com/PHP-Find-loc...ict131475.html
Visit Topic URL to contact author (reg. req’d). Report

abuse:
http://www.dbForumz.com/eform.php?p=438714

gethostbynamel($dns_name_of_computer).


I don’t have DNS on my pc, so I tried
gethostbynamel(’localhost’)
but it returns 127.0.0.1[/quote:5b9ab702e4]

It works! must do it this way:
$hosts=gethostbynamel(’’); (see
http://ca2.php.net/manual/en/functio...ostbynamel.php)

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-Find-loc...ict131475.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=438856
Jul 17 '05 #5
"steve" wrote:
[quote:a576311143="steve"][quote:a576311143="Chung Leong"]"steve" <Us************@dbForumz.com> wrote in message
news:Tv****************@cyclops.nntpserver.com...
Hi, I am running apache on local pc/ under Windows.

I need to figure out the ip number of the pc inside PHP. This is

the
number available when you do ipconfig, and not the 127.0.0.1!

So the slow way I have figured out is to do a system call to doc,
using `ipconfig`, and then regex the result and figure out the

ip.
Is there a fater/more efficient way to do this?

--
http://www.dbForumz.com/ This article was posted by

author’s request
Articles individually checked for conformance to usenet standards
Topic URL:

http://www.dbForumz.com/PHP-Find-loc...ict131475.html
Visit Topic URL to contact author (reg. req’d). Report

abuse:
http://www.dbForumz.com/eform.php?p=438714

gethostbynamel($dns_name_of_computer).


I don’t have DNS on my pc, so I tried
gethostbynamel(’localhost’)
but it returns 127.0.0.1[/quote:a576311143]

It works! must do it this way:
$hosts=gethostbynamel(’’); (see
http://ca2.php.net/manual/en/functio...stbynamel.php)[/quote:a576311143]

And a quick note, the $hosts variable above is an array. Take
$hosts[0] as the IP number!
Jul 17 '05 #6

"steve" <Us************@dbForumz.com> wrote in message
news:wk*****************@cyclops.nntpserver.com...
> gethostbynamel($dns_name_of_computer).
I don't have DNS on my pc, so I tried
gethostbynamel('localhost')
but it returns 127.0.0.1[/quote:a576311143]

It works! must do it this way:
$hosts=gethostbynamel(''); (see

http://ca2.php.net/manual/en/functio...stbynamel.php)[/quote:a576311143]
And a quick note, the $hosts variable above is an array. Take
$hosts[0] as the IP number!


Just to clarify: getbyhostname('localhost') *should* return 127.0.0.1, since
it almost always
defined as such in your hosts file. You should actually either use '', like
you did, or your known
machine name 'someserver.somedomain.com' if you want its actual IP.

And you don't need to have DNS on your PC, if you can look up *any* hostname
(not already
defined in your hosts file) then you are accessing a DNS server somewhere.
(look up anything
via nslookup at a command line, and it will tell you what server you are
currently using as part of
its response.)
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Olly | last post by:
Find an id number not present in a linking table I have a linking table (tblPayment) that monitors the subscriptions from members. However, I need a query that can compare the ID number fields...
12
by: Klaus Drechsel | last post by:
My Problem: The Function Dispose on a IDisposable shuld be called on the last reference to this instance. Can I get the number of references. to an object? Klaus Drechsel
4
by: Mahesh BS | last post by:
Hello, I need to write a query to find out a set of missing number in a given sequence. Eg : a Column in some table has the following data
10
by: svlsr2000 | last post by:
Can any one give me best algorithm to find nth ugly number.
1
by: Simon | last post by:
Dear reader, Is there a function or VBA code available to find the week number out of a date field. You can find the year with Year(date field) but now I need the week number out of a...
2
by: rajukotla | last post by:
How to find out the number of days in a financial year. suppose from date is sep1st,2006.and to date is aug24th,2009. the entire range involves financial years.i.e., ...
2
by: Revathi Balakrishnan | last post by:
Hi All Is it possible to find out the number of frames the page contain? For example my page is divided in to three frames using frameset tag, and one of my frame has i frame also. Like such...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.