Solved

Does $_SERVER['REMOTE_ADDR'] always returns the same value for the same PC

Posted on 2014-09-21
20
316 Views
Last Modified: 2014-09-22
Hi Experts

Does $_SERVER['REMOTE_ADDR']

always returns the same value for the same PC connected and it doesn´t matter the day

or it changes  by session, by date, etc

Thanks in advance!
0
Comment
Question by:Eduardo Fuerte
  • 9
  • 5
  • 4
  • +1
20 Comments
 
LVL 58

Assisted Solution

by:Gary
Gary earned 75 total points
Comment Utility
It's always the 'same' but with the proviso the computer could be using a proxy so the IP won't be the users IP and IP addresses can be refreshed especially with home ISP's
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 350 total points
Comment Utility
In a short period of time, it will only change if the client is using something like dial-up AOL, where the ISP provides "blocks" of IP addresses.  Most home clients in the USA today have a high-speed connection and use a stable IP address for a cable modem or something like that.  Over longer periods of time clients may change providers and this will change the IP address.  Or the providers may make changes.

In my home I have three PCs, a Mac, three iPhones.  All of them can be used to browse the web.  All of them have different IP addresses.  I sometimes use the computer at the library, too, so you may get me from any of several IP addresses, sometimes at the same time.

What is the motivation behind the question?
0
 
LVL 82

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 75 total points
Comment Utility
On a number of websites where I track $_SERVER['REMOTE_ADDR'] , the 'known' IP addresses never change.  That includes my own and my clients.  But I also have several public IP addresses so you might not be able to track 'me' simply by IP address.  And that's without using a proxy.

In addition, a couple of my clients have 4 or more people working from thru same public IP address.  That often happens with businesses when they have a number of employees but only one internet connection.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
Also, $_SERVER['REMOTE_ADDR'] is part of the information that the web server passes to PHP.  It also passes it to any other server side programming language that is used like ASP, ASP.NET, Perl, and Python.  The exact syntax is different for each language but the information is always the same.  The web server gets the info from the TCP/IP connection that it listens to.
0
 

Author Comment

by:Eduardo Fuerte
Comment Utility
Hello

Thank you for the interactions.

The motivation is due my site needs to construct phisical tables to be used temporarily (temporary  tables doesn't work)
and then droped.
I'm using  "t_".$_SERVER['REMOTE_ADDR'] to construct the table and then drop it in the same session.

If the user go a way and the server couldn't drop the table maybe the next time the user access the site it could be done.
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
Temporary table to store what, seems a crazy way of doing it.
Why not just store the data in a normal table and remove the rows when finished.
0
 

Author Comment

by:Eduardo Fuerte
Comment Utility
Because if say... more than ONE person use the site at the same time they couldn't populate the same table with diferent data...
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
If the unique key is the IP you are already in trouble since you could have a 100 computers behind the same IP
Regardless you are using the IP for the table name so why not just use the IP as the unique ID in each row therefore each row is unique to that person (not forgoing what I just said)
0
 

Author Comment

by:Eduardo Fuerte
Comment Utility
Sorry I don't understand your reply

Your suggestion is to use the physical IP of the computer connected instead of $_SERVER['REMOTE_ADDR']   that is in the PHP server?
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
Uh?
$_SERVER['REMOTE_ADDR']  is the IP of the user.
You have one table and when you add a row you use the IP to identify that row with the user.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:Eduardo Fuerte
Comment Utility
By now I prefer to maintain $_SERVER['REMOTE_ADDR']  to create and drop tables
since the routine is done and works...
0
 

Author Closing Comment

by:Eduardo Fuerte
Comment Utility
Thank you for the assistance!
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
Let's go back to this: "What is the motivation behind the question?"  Please fly up to 50,000 feet and look down on the surface of the planet, not specifically at the way you see the problem, then give us a simple and non-technical description of what you're trying to do.  Something like, "I want to sell donuts to unicorns."  Once we understand the design pattern we may be able to suggest more mainstream solutions.

Or consider posting a new question.
0
 

Author Comment

by:Eduardo Fuerte
Comment Utility
I really don't understand what you means here.

As I said:

"The motivation is due my site needs to construct phisical tables to be used temporarily (temporary  tables doesn't work)
 and then droped.
 I'm using  "t_".$_SERVER['REMOTE_ADDR'] to construct the table and then drop it in the same session."

After reading the replies:

For me  $_SERVER['REMOTE_ADDR']  reasonably  attends the purpose of an unique identificator of a net user to be used in a name of a table or, optionaly to be used to identificate a table line like Gary correctly suggested.

Could you clarify ?
0
 

Author Comment

by:Eduardo Fuerte
Comment Utility
Sorry,
After reflect in your words.
I'm constructing a financial system converting it from a desktop one... to attend some filantropical institutions....
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
$_SERVER['REMOTE_ADDR'] can be guaranteed to Not work for your purpose at some time.  I always use the 'session_id' for individual identification.  It is commonly used for shopping carts because it can almost be guaranteed to be unique.  I can make connections from 3 to 5 browsers each on 10 computers here and you will Not be able to tell them apart using $_SERVER['REMOTE_ADDR'].  If I use Sessions and session_id, each one will be uniquely identified even when they all connect at the same time thru my public IP address which will be the Same for all of them.

http://us2.php.net/manual/en/book.session.php
0
 

Author Comment

by:Eduardo Fuerte
Comment Utility
Thanks, Dave!

I tried it, it's really much better.
I'm going to use only the 12 last positions to keep table name's strategy due the name limitations, otherwise use it inside a column for user identification....

   $a = session_id();
        if(empty($a))
        { 
            session_start();
       }
        $tab_final = "t_" . substr($a,22,12);

Open in new window

0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
That is compromising the uniqueness of the session_id.  Use all the characters because that's what the 'uniqueness' is based on.  The difference between two session_id's can be as little as one character anywhere in the string.
0
 

Author Comment

by:Eduardo Fuerte
Comment Utility
Ok, Dave!

I'm going to follow your advice.
The better approach is to use session_id() as a line identificator.

Thanks again!
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
You're welcome.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now