Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
REMOTE_ADDR not working..?!
Old 09-19-2010, 04:31 AM REMOTE_ADDR not working..?!
Average Talker

Posts: 22
Trades: 0
I have a gaming script that sniff the user's IP and put it into my database if they visit a specific page, I've been using the $_SERVER['REMOTE_ADDR'] function to do this.

But a few days ago when I check the database, all the user's IP in the IP column are the same, they all had my server IP.
The same thing also happen to my phpBB, when I check the online users, they all had the same IP.

How did this happen and how do I fix it?

Last edited by progogi; 09-19-2010 at 04:58 AM..
progogi is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-19-2010, 12:50 PM Re: REMOTE_ADDR not working..?!
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
try using getenv("REMOTE_ADDR");
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-19-2010, 01:35 PM Re: REMOTE_ADDR not working..?!
Average Talker

Posts: 22
Trades: 0
nothing changed, still getting the same IP
progogi is offline
Reply With Quote
View Public Profile
 
Old 09-19-2010, 01:47 PM Re: REMOTE_ADDR not working..?!
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
What does REMOTE_HOST return?
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-19-2010, 01:56 PM Re: REMOTE_ADDR not working..?!
Average Talker

Posts: 22
Trades: 0
it returns blank...
progogi is offline
Reply With Quote
View Public Profile
 
Old 09-19-2010, 02:16 PM Re: REMOTE_ADDR not working..?!
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
It maybe that your hosting provider has overwritten the environment variable with a fixed value in that case.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-19-2010, 07:15 PM Re: REMOTE_ADDR not working..?!
Ultra Talker

Posts: 366
Name: Steve
Location: Miami, FL, Earth
Trades: 0
create a new page called "test.php" and put one line in it: <?php php_info(); ?>

Then open that page and search for your ip address (go to www.whatsmyip.org to find it).

Also, review the server variables section and see what's going on there...

As chris says, your server config may be such that you can't capture remote IPs. If so, get a new host.
__________________
- Steve

President,
Please login or register to view this content. Registration is FREE
smoseley is offline
Reply With Quote
View Public Profile Visit smoseley's homepage!
 
Old 09-19-2010, 11:40 PM Re: REMOTE_ADDR not working..?!
Average Talker

Posts: 22
Trades: 0
Well, I could find my IP in the phpinfo page
but it's written in the same row as HTTP_X_FORWARDED_FOR and HTTP_X_REAL_IP

the value of REMOTE_ADDR variable is exactly the server IP address

is it okay to use HTTP_X_FORWARDED_FOR or HTTP_X_REAL_IP instead of REMOTE_ADDR?
progogi is offline
Reply With Quote
View Public Profile
 
Old 09-20-2010, 03:12 PM Re: REMOTE_ADDR not working..?!
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
It sounds like your host is proxying requests. Check that with inspecting the "$HTTP_PROXY_CONNECTION"

There is absolutely no reason why you shouldn't use the "hidden" variables

Rooting around Google results turned up this code
PHP Code:
function real_ip(){
    if(isset(
$_SERVER['HTTP_X_FORWARDED_FOR'])){
        
$_SERVER['REMOTE_ADDR']=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }elseif(isset(
$_SERVER['HTTP_X_REAL_IP']){
        
$_SERVER['REMOTE_ADDR']=$_SERVER['HTTP_X_REAL_IP'];
    }
return 
$_SERVER['REMOTE_ADDR'];

__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-21-2010, 03:16 AM Re: REMOTE_ADDR not working..?!
Average Talker

Posts: 22
Trades: 0
Quote:
Originally Posted by chrishirst View Post
It sounds like your host is proxying requests. Check that with inspecting the "$HTTP_PROXY_CONNECTION"

There is absolutely no reason why you shouldn't use the "hidden" variables
I tried to contact them about that, but haven't receive any response, perhaps I should just move to another host...
But, I tried HTTP_PROXY_CONNECTION and I got nothing...
Quote:
Originally Posted by chrishirst View Post
Rooting around Google results turned up this code
PHP Code:
function real_ip(){
    if(isset(
$_SERVER['HTTP_X_FORWARDED_FOR'])){
        
$_SERVER['REMOTE_ADDR']=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }elseif(isset(
$_SERVER['HTTP_X_REAL_IP']){
        
$_SERVER['REMOTE_ADDR']=$_SERVER['HTTP_X_REAL_IP'];
    }
return 
$_SERVER['REMOTE_ADDR'];

a ")" is missing from line 5 of the code you gave me but anyways, I tried the script on a testing page and just like HTTP_PROXY_CONNECTION it returns blank
I guess I'll just stick to HTTP_X_FORWADED_FOR for now...

Thanks for all your help
progogi is offline
Reply With Quote
View Public Profile
 
Old 09-21-2010, 03:44 AM Re: REMOTE_ADDR not working..?!
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Is this one of the "well known" hosting companies by some chance?
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-21-2010, 07:59 AM Re: REMOTE_ADDR not working..?!
Average Talker

Posts: 22
Trades: 0
no, actually. I'm using a small company hosting, they have great hosting features,low price and pretty good uptime but I guess that doesn't make them to have a good support
progogi is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to REMOTE_ADDR not working..?!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.35447 seconds with 12 queries