get ip address in php - Web Development and Web Design Codes


Send Email to user for Free No Credit Card Required | Now Send Lot's Of Emails To Your Users Daily For Free!
✓ Free Emails Daily | ✓ Drag & Drop Builder | ✓ Beautiful Email Templates | ✓ Mobile Friendly Emails

Tuesday, April 3, 2018

get ip address in php

get ip address in php

get ip address in php
get ip address in php
Hi Friends in this lesson we are going to learn how to get visitor ip address and website host name using php...
in many times we need to collect user ip address to track user activity and other security can get user ip address easily using php..
 $_SERVER['REMOTE_ADDR'] are use to Detect ip address of a user..
you can print current user ip by the below method

but sometimes $_SERVER['REMOTE_ADDR'] method can't detect the current user ip address ..because they are using vpn or proxy..
You can use below codes to detect user ip address..
function getUserIP(){
        //Check if ip from share INTERNET
        $ip = $_SERVER['HTTP_CLIENT_IP'];
        //check ip ip pass from proxy
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        $ip = $_SERVER['REMOTE_ADDR'];
    return $ip;
//Get Host Name
$hostname = getenv('HTTP_HOST');
echo 'You IP:--- '.getUserIP();
echo '<br/>Your Host Name:-- '.$hostname;

That's it Friends how to get ip address in php..i hope you enjoy this article  ..Please share with your friends ..Thank You...

No comments:

Post a Comment

Thank You for Your Comment

Note: Only a member of this blog may post a comment.