PHP code to save visitor's IP address in an excel file visiting on a webpage on my website

142 Views Asked by At

I want to save all the IP data of the visitors browsing a webpage of my website. I already have a code for the process, however, I want to save the data in an excel file and send an email with the sheet. Is that possible?

function getUserIpAddr(){
    if(!empty($_SERVER['HTTP_CLIENT_IP'])){
        //ip from share internet
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    }elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
        //ip pass from proxy
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }else{
        $ip = $_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}

echo 'User Real IP - '.getUserIpAddr();
0

There are 0 best solutions below