$_SERVER[“SCRIPT_URI”] not working? alternative?

前端 未结 11 2530
北恋
北恋 2020-12-17 17:17

This is odd, but for some reason the $_SERVER[\"SCRIPT_URI\"] will not return the domain name when I am in child/sub-pages but will only work on the main page.

11条回答
  •  独厮守ぢ
    2020-12-17 17:48

    Late late reply. I use this piece of script to store information in my db. Hope this might help someone. How to get your full url and the ip address of the client access from.

    if (!empty($_SERVER['HTTP_CLIENT_IP'])){
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    //Is it a proxy address
    }elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }else{
      $ip=$_SERVER['REMOTE_ADDR'];
    }
    
    $url = $_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'];
    
    echo $ip;
    echo "
    "; echo $url;

提交回复
热议问题