
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Identify Server IP Address in PHP
The server IP can be identified with the below line of code −
$_SERVER['SERVER_ADDR'];
The port can be identified using the below line of code −
$_SERVER['SERVER_PORT'];
For PHP version 5.3 and higher, the following lines of code can be used −
$host_addr= gethostname(); $ip_addr = gethostbyname($host_addr);
This can be used when a stand-alone script is being run (which is not running via the web server).
Advertisements