Jump to content
php.lv forumi

getip


renathy

Recommended Posts

nju es, piemēram, aplikācijas init daļā izpildu

define('IP', $_SERVER['REMOTE_ADDR']);

un pēc tam lietoju konstanti IP visur kur vien vajag ip. man vimaz tā ir vienkāršāk un ātrāk.

 

par tādu HTTP_CLIENT_IP vispār pirmā dzirdēšana! ;) uzgūglēju vienīgi to, ka tas ir extra headeris, ko dažreiz pievieno proxy. mb tas arī var noderēt. un tādā gadījumā īsto ip varētu iegūt ar

echo isset($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : $_SERVER['REMOTE_ADDR'];

bet es uz to bez īpašas vajadzības neiespringtu un paliktu pie vnk $_SERVER['REMOTE_ADDR']

Link to comment
Share on other sites

es izmantoju šitādu:

function ip()
{
       $IP=(isset($_SERVER['REMOTE_ADDR'])?$_SERVER['REMOTE_ADDR']:'').
       (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']!='unknown'?' fwd '.$_SERVER['HTTP_X_FORWARDED_FOR']:'').
       (isset($_SERVER['HTTP_CLIENT_IP'])?' client_ip '.$_SERVER['HTTP_CLIENT_IP']:'').
       (isset($_SERVER['HTTP_VIA'])?' via '.$_SERVER['HTTP_VIA']:'');
       return $IP;
}

Edited by Klez
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...