GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   How to get clients ip in php (https://gfy.com/showthread.php?t=509551)

E Guru 08-29-2005 10:12 AM

How to get clients ip in php
 
I am having a problem with some server load sharing and getting the clients correct ip.
When I use xforwardedfor it gets the first machines ip (servers ip) and I use remote_addr it gets the 2nd machines ip.
I tried using ['HTTP_CLIENT_IP'] but it shows ip blank.

Does anyone know what I can use grab the ip from the users browser?

broke 08-29-2005 10:14 AM

['REMOTE_ADDR']

E Guru 08-29-2005 10:17 AM

Quote:

Originally Posted by broke
['REMOTE_ADDR']

That doesn't work as I said above

broke 08-29-2005 10:18 AM

Don't mind me... I'm retarded.

Calvinguy 08-29-2005 10:21 AM

$_server["remote_addr"]

Manowar 08-29-2005 10:22 AM

Quote:

Originally Posted by Calvinguy
$_server["remote_addr"]

:thumbsup

E Guru 08-29-2005 10:24 AM

Quote:

Originally Posted by Calvinguy
$_server["remote_addr"]

No, that does not work. The whole variable does not work.

Here is what they told me.
Its passed as a variable
"x-client-ip"
in unix if you want to set the log to read it, you would use this:
LogFormat "\"%{X-Client-IP}i\" %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

Well, how would I get that in php?

jwerd 08-29-2005 10:24 AM

If
$_SERVER['REMOTE_ADDR'] doesn't work, superglobals may be broken :(

Try:

$ip = getenv('REMOTE_ADDR');
echo $ip

Quickdraw 08-29-2005 10:32 AM

$_server[http_pc_remote_addr]

E Guru 08-29-2005 10:36 AM

Quote:

Originally Posted by lamerhooD
If
$_SERVER['REMOTE_ADDR'] doesn't work, superglobals may be broken :(

Try:

$ip = getenv('REMOTE_ADDR');
echo $ip

No man, it works. It just doesn't get the correct ip.

E Guru 08-29-2005 10:36 AM

Quote:

Originally Posted by Quickdraw
$_server[http_pc_remote_addr]

Comes up blank :helpme

4Pics 08-29-2005 10:37 AM

Are you using a proxy?

broke 08-29-2005 10:39 AM

Have you tried x-forwarded-client?

E Guru 08-29-2005 10:40 AM

Quote:

Originally Posted by 4Pics
Are you using a proxy?

Not myself, but server seams thinks I am. That is why I am trying to grab the IP from the users browser.

E Guru 08-29-2005 10:43 AM

Quote:

Originally Posted by broke
Have you tried x-forwarded-client?


Returns a 0

broke 08-29-2005 10:54 AM

How about $_GET['x-client-ip']

E Guru 08-29-2005 10:58 AM

Quote:

Originally Posted by broke
How about $_GET['x-client-ip']

No go, comes up blank. You would think that would do it though.

E Guru 08-29-2005 11:00 AM

This is the code I used

<?php

$RIGHT_IP = $_GET['x-client-ip'];

?>

<? echo "$RIGHT_IP"; ?>

E Guru 08-29-2005 11:02 AM

Here is what they just said also:
If it were in unix it would be
LogFormat "\"%{X-Client-IP}i\" %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined


Wtf does that mean?

Quickdraw 08-29-2005 11:07 AM

Have you tried echo phpinfo(); to see what might work?

I grabbed this function from php.net and added the echo.. maybe?

PHP Code:

function getip() {
   if (
getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
   
$ip getenv("HTTP_CLIENT_IP");

   else if (
getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
   
$ip getenv("HTTP_X_FORWARDED_FOR");

   else if (
getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
   
$ip getenv("REMOTE_ADDR");

   else if (isset(
$_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
   
$ip $_SERVER['REMOTE_ADDR'];

   else
   
$ip "unknown";

   return(
$ip);

echo 
getip(); 


E Guru 08-29-2005 11:17 AM

Quikdraw - I tried the phpinfo and found the variable that held the ip

You rock :pimp

Got it working

jwerd 08-29-2005 11:19 AM

Quote:

Originally Posted by E Guru

<? echo "$RIGHT_IP"; ?>

An easier way to do this is:

<?=$RIGHT_IP?>

:thumbsup

broke 08-29-2005 11:21 AM

So what was the variable?

E Guru 08-29-2005 12:13 PM

Quote:

Originally Posted by broke
So what was the variable?

HTTP_X_CLIENT_IP


All times are GMT -7. The time now is 09:42 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123