IP of the server
Moderator: General Moderators
-
vijayanand16
- Forum Newbie
- Posts: 12
- Joined: Fri Jan 30, 2004 4:57 pm
IP of the server
How to get the ip address of the server from the PHP code
-
Straterra
- Forum Regular
- Posts: 527
- Joined: Mon Nov 24, 2003 8:46 am
- Location: Indianapolis, Indiana
- Contact:
You could just open a socket and retrieve the information from http://www.whatismyip.com and then parse through that information to get your IP.
-
vijayanand16
- Forum Newbie
- Posts: 12
- Joined: Fri Jan 30, 2004 4:57 pm
How i get to know the server name?
Last edited by vijayanand16 on Fri Jan 30, 2004 5:50 pm, edited 1 time in total.
A MUCH MUCH easier method is to use the built in $_SERVER array.
$_SERVER[SERVER_ADDR] should get you what you need. Check the PHP manual at: http://ca.php.net/reserved.variables for more info.
$_SERVER[SERVER_ADDR] should get you what you need. Check the PHP manual at: http://ca.php.net/reserved.variables for more info.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
-
vijayanand16
- Forum Newbie
- Posts: 12
- Joined: Fri Jan 30, 2004 4:57 pm
Ya, I know. $_SERVER[SERVER_ADDR] will get you the server address. $_SERVER[REMOTE_ADDR] will get you the client's ip. Run this command in a PHP page and you'll see what I mean: "print_r($_SERVER);". That will dump $_SERVER to your browser.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
My fault. That particular index (SERVER_ADDR) is not listed on the page I mentioned. However, when you print out the server vars, you WILL see it. I don't know what else to say. The only problems I can see is if you're running PHP from the command line, or if for some reason, your server doesn't create certain variables. Beyond that, it's there.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Check what's in the $_SERVER array by doing:
Mac
Code: Select all
echo '<pre>';
print_r($_SERVER);
echo '</pre>';