954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to get server address using php

hi friends

I have run the one php script live server( www.live.com/samplee.php ) . this file access the staging server and run the staging server php file and display the result.

But I need the live server address server name also display in the staging serevr php page result page.

How can i get the live server address?

Please help me

vssp
Junior Poster
199 posts since Jul 2006
Reputation Points: 5
Solved Threads: 5
 

[PHP]echo $_SERVER['HTTP_HOST'];[/PHP]

DanceInstructor
Posting Whiz
368 posts since Feb 2005
Reputation Points: 17
Solved Threads: 14
 

hi Friend
Thanks for your quick replay.

This code get the staging server ip address but I need Live server address

Please advice

vssp
Junior Poster
199 posts since Jul 2006
Reputation Points: 5
Solved Threads: 5
 

That code should not give you an ip address, unless the server isnt setup with a host name. I dont understand your problem if you are calling a page on another server you already know the other server's host name...

DanceInstructor
Posting Whiz
368 posts since Feb 2005
Reputation Points: 17
Solved Threads: 14
 

try this:

<?
$address = getenv("REMOTE_ADDR");
echo $address;
// Or simply use a Superglobal ($_SERVER or $_ENV)
$ip = $_SERVER['REMOTE_ADDR'];
?>

The function 'getenv' does not work if your Server API is ASAPI (IIS).
So, try to don't use getenv('REMOTE_ADDR'), but $_SERVER["REMOTE_ADDR"].

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

Thanks for your reply

vssp
Junior Poster
199 posts since Jul 2006
Reputation Points: 5
Solved Threads: 5
 
<?php

echo "server address:".$_SERVER['SERVER_ADDR']."<br/>";

?>
chathurika1981
Newbie Poster
1 post since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

This is the only way to got your server real outside/wan IP

<?php
echo file_get_contents("http://ip6.me/");
?>
bab2501
Newbie Poster
1 post since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You