我使用时页面加载两次(带有短链接重定向的php重定向)

I have develop a website to take a statistical information about specific link first of all

  • I make a short_link that point to the that specific link (using Google Shortlink API)

  • Then that short_link point to other page in my site that take statistical information like (IP, Country code , date , time ,.... )

  • Then at the end of this page there is a redirect to the destination website (Link)

         $ip = $_SERVER['REMOTE_ADDR'];
    
        $detect = new Mobile_Detect;
         $deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');
    
         $device=$deviceType;
    
    
        $countryid=$this->geoCheckIP($ip);
        $countryid=substr ($countryid["country"],0,2);
    
        $date = date('Y-m-d');
        $time = date('H:i:s');
    
    
    
        $this->statistical->Addvisit($device,$countryid,$ip,$date,$time);
        redirect($url);
    

the above code work correctly and retrieve a correct data but some time it execute twice ( especially when there are slow internet connection ) and in the second load (execution) it give an error data (IP, countryid ,...) How can I solve that ???? thank you :)