- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to 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).
- Related Articles
- How to redirect domain according to country IP address in PHP?
- Difference between Static IP Address and Dynamic IP Address
- How to get the ip address in C#?
- How to validate the IP address using PowerShell?
- How to get a Docker Container IP address?
- How to get IP address settings using PowerShell?
- Validate IP Address in C++
- Validate IP Address in C#
- Validate IP Address in Python
- Difference between MAC Address and IP Address
- Difference between IP Address and MAC Address
- Alias/Secondary IP Address
- How to get current Wi-Fi IP address in android?
- How to get the server IP with Laravel?
- Defanging an IP Address in Python

Advertisements