Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 08-29-2005, 10:12 AM   #1
E Guru
Confirmed User
 
Join Date: Jul 2005
Posts: 658
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?
E Guru is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2005, 10:14 AM   #2
broke
Confirmed User
 
Join Date: Aug 2003
Location: Someplace Windy
Posts: 4,501
['REMOTE_ADDR']
__________________
Perfect Gonzo

Last edited by broke; 08-29-2005 at 10:16 AM..
broke is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2005, 10:17 AM   #3
E Guru
Confirmed User
 
Join Date: Jul 2005
Posts: 658
Quote:
Originally Posted by broke
['REMOTE_ADDR']
That doesn't work as I said above
E Guru is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2005, 10:18 AM   #4
broke
Confirmed User
 
Join Date: Aug 2003
Location: Someplace Windy
Posts: 4,501
Don't mind me... I'm retarded.
__________________
Perfect Gonzo
broke is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2005, 10:21 AM   #5
Calvinguy
Confirmed User
 
Join Date: Oct 2002
Location: European Union
Posts: 1,752
$_server["remote_addr"]
Calvinguy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2005, 10:22 AM   #6
Manowar
jellyfish  
 
Join Date: Dec 2003
Posts: 71,528
Quote:
Originally Posted by Calvinguy
$_server["remote_addr"]
Manowar is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2005, 10:24 AM   #7
E Guru
Confirmed User
 
Join Date: Jul 2005
Posts: 658
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?
E Guru is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2005, 10:24 AM   #8
jwerd
Confirmed User
 
Industry Role:
Join Date: Jun 2003
Location: Costa Rica
Posts: 1,953
If
$_SERVER['REMOTE_ADDR'] doesn't work, superglobals may be broken

Try:

$ip = getenv('REMOTE_ADDR');
echo $ip
__________________
Yii Framework Guru - Seasoned PHP vet - Partner @ XXXCoupon.com
jwerd is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2005, 10:32 AM   #9
Quickdraw
Confirmed User
 
Join Date: Mar 2004
Location: → → →
Posts: 1,717
$_server[http_pc_remote_addr]
Quickdraw is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2005, 10:36 AM   #10
E Guru
Confirmed User
 
Join Date: Jul 2005
Posts: 658
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 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2005, 10:36 AM   #11
E Guru
Confirmed User
 
Join Date: Jul 2005
Posts: 658
Quote:
Originally Posted by Quickdraw
$_server[http_pc_remote_addr]
Comes up blank
E Guru is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2005, 10:37 AM   #12
4Pics
Confirmed User
 
Industry Role:
Join Date: Dec 2001
Posts: 7,952
Are you using a proxy?
4Pics is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2005, 10:39 AM   #13
broke
Confirmed User
 
Join Date: Aug 2003
Location: Someplace Windy
Posts: 4,501
Have you tried x-forwarded-client?
__________________
Perfect Gonzo
broke is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2005, 10:40 AM   #14
E Guru
Confirmed User
 
Join Date: Jul 2005
Posts: 658
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 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2005, 10:43 AM   #15
E Guru
Confirmed User
 
Join Date: Jul 2005
Posts: 658
Quote:
Originally Posted by broke
Have you tried x-forwarded-client?

Returns a 0
E Guru is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2005, 10:54 AM   #16
broke
Confirmed User
 
Join Date: Aug 2003
Location: Someplace Windy
Posts: 4,501
How about $_GET['x-client-ip']
__________________
Perfect Gonzo
broke is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2005, 10:58 AM   #17
E Guru
Confirmed User
 
Join Date: Jul 2005
Posts: 658
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 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2005, 11:00 AM   #18
E Guru
Confirmed User
 
Join Date: Jul 2005
Posts: 658
This is the code I used

<?php

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

?>

<? echo "$RIGHT_IP"; ?>
E Guru is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2005, 11:02 AM   #19
E Guru
Confirmed User
 
Join Date: Jul 2005
Posts: 658
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?
E Guru is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2005, 11:07 AM   #20
Quickdraw
Confirmed User
 
Join Date: Mar 2004
Location: → → →
Posts: 1,717
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(); 
Quickdraw is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2005, 11:17 AM   #21
E Guru
Confirmed User
 
Join Date: Jul 2005
Posts: 658
Quikdraw - I tried the phpinfo and found the variable that held the ip

You rock

Got it working
E Guru is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2005, 11:19 AM   #22
jwerd
Confirmed User
 
Industry Role:
Join Date: Jun 2003
Location: Costa Rica
Posts: 1,953
Quote:
Originally Posted by E Guru

<? echo "$RIGHT_IP"; ?>
An easier way to do this is:

<?=$RIGHT_IP?>

__________________
Yii Framework Guru - Seasoned PHP vet - Partner @ XXXCoupon.com
jwerd is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2005, 11:21 AM   #23
broke
Confirmed User
 
Join Date: Aug 2003
Location: Someplace Windy
Posts: 4,501
So what was the variable?
__________________
Perfect Gonzo
broke is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-29-2005, 12:13 PM   #24
E Guru
Confirmed User
 
Join Date: Jul 2005
Posts: 658
Quote:
Originally Posted by broke
So what was the variable?
HTTP_X_CLIENT_IP
E Guru is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.