Solved

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

Posted on 2014-09-21
20
320 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
ID: 40335360
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
ID: 40335398
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 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 75 total points
ID: 40335468
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 83

Expert Comment

by:Dave Baldwin
ID: 40335477
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
ID: 40335689
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
ID: 40335690
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
ID: 40335698
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
ID: 40335700
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
ID: 40335711
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
ID: 40335715
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:Eduardo Fuerte
ID: 40335720
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
ID: 40335729
Thank you for the assistance!
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40335730
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
ID: 40335757
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
ID: 40335759
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 83

Expert Comment

by:Dave Baldwin
ID: 40335761
$_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
ID: 40335772
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 83

Expert Comment

by:Dave Baldwin
ID: 40335780
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
ID: 40336229
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 83

Expert Comment

by:Dave Baldwin
ID: 40337005
You're welcome.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How can i modify my File download link ? 6 45
Apache/PHP: Cannot make phpinfo() and phpmyadmin work 4 33
phpmyadmin 3 32
Sql query on a varchar that is numeric. 8 24
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
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.

929 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

18 Experts available now in Live!

Get 1:1 Help Now