0

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();
  • 2
    Yes it's possible although if your site has many visitors you might have issues with concurrent write access to the file. Probably better to store it in a database and then export from there to Excel/CSV when you want to send the email. – ADyson Sep 29 '21 at 11:55
  • 1
    _"and send an email with the sheet"_ - but presumably not for every single visit. So that part of the functionality is something you should schedule via cron. – CBroe Sep 29 '21 at 12:17

0 Answers0