Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 380
  • Last Modified:

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

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
Eduardo Fuerte
Asked:
Eduardo Fuerte
  • 9
  • 5
  • 4
  • +1
3 Solutions
 
GaryCommented:
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
 
Ray PaseurCommented:
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
 
Dave BaldwinFixer of ProblemsCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Dave BaldwinFixer of ProblemsCommented:
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
 
Eduardo FuerteAuthor Commented:
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
 
GaryCommented:
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
 
Eduardo FuerteAuthor Commented:
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
 
GaryCommented:
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
 
Eduardo FuerteAuthor Commented:
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
 
GaryCommented:
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
 
Eduardo FuerteAuthor Commented:
By now I prefer to maintain $_SERVER['REMOTE_ADDR']  to create and drop tables
since the routine is done and works...
0
 
Eduardo FuerteAuthor Commented:
Thank you for the assistance!
0
 
Ray PaseurCommented:
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
 
Eduardo FuerteAuthor Commented:
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
 
Eduardo FuerteAuthor Commented:
Sorry,
After reflect in your words.
I'm constructing a financial system converting it from a desktop one... to attend some filantropical institutions....
0
 
Dave BaldwinFixer of ProblemsCommented:
$_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
 
Eduardo FuerteAuthor Commented:
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
 
Dave BaldwinFixer of ProblemsCommented:
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
 
Eduardo FuerteAuthor Commented:
Ok, Dave!

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

Thanks again!
0
 
Dave BaldwinFixer of ProblemsCommented:
You're welcome.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 9
  • 5
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now