Can I get the IP address from a visitor?
Can I get the IP address from a visitor?
am 01.12.2009 00:47:28 von Lars Kristiansson
Hi!
This is probably the wrong forum. Please redirect me if im out of place.
I would like to find out what IP address my visitor uses when visiting a php
script page on my domain. This page would contain a form in which the
visitor would state his/her message.
My goal is to create purchase-orders written on unique files, and to
separate them my idea was to baptize files with the IP addresses, which
would ive each visitor an unique purchase-order...
Any hints to a newbie?
Cheers, Lars
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: Can I get the IP address from a visitor?
am 01.12.2009 11:12:12 von Network Admin
That would be in one of the $_SERVER[] variables.
Look here for more info:
http://uk.php.net/manual/en/reserved.variables.server.php
HTH
J
-----Original Message-----
From: Lars Kristiansson [mailto:lasse@naturbilden.se]
Sent: 30 November 2009 23:47
To: php-general@lists.php.net
Subject: [PHP] Can I get the IP address from a visitor?
Hi!
This is probably the wrong forum. Please redirect me if im out of place.
I would like to find out what IP address my visitor uses when visiting a php
script page on my domain. This page would contain a form in which the
visitor would state his/her message.
My goal is to create purchase-orders written on unique files, and to
separate them my idea was to baptize files with the IP addresses, which
would ive each visitor an unique purchase-order...
Any hints to a newbie?
Cheers, Lars
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Can I get the IP address from a visitor?
am 01.12.2009 11:17:01 von Lester Caine
Lars Kristiansson wrote:
> Hi!
>
> This is probably the wrong forum. Please redirect me if im out of place.
>
> I would like to find out what IP address my visitor uses when visiting a
> php script page on my domain. This page would contain a form in which
> the visitor would state his/her message.
>
> My goal is to create purchase-orders written on unique files, and to
> separate them my idea was to baptize files with the IP addresses, which
> would ive each visitor an unique purchase-order...
>
> Any hints to a newbie?
http://uk3.php.net/manual/en/reserved.variables.server.php
'REMOTE_ADDR'
But don't rely on it to be the same each time for a customer. If they are on a
shared connection then the ISP may give them a different IP each time they
access the internet.
--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Can I get the IP address from a visitor?
am 01.12.2009 12:07:02 von Ali Asghar Toraby Parizy
It is very simple:
$ip=$_SERVER['REMOTE_ADDR'];
On Tue, Dec 1, 2009 at 1:47 PM, Lester Caine wrote:
> Lars Kristiansson wrote:
>>
>> Hi!
>>
>> This is probably the wrong forum. Please redirect me if im out of place.
>>
>> I would like to find out what IP address my visitor uses when visiting a
>> php script page on my domain. This page would contain a form in which the
>> visitor would state his/her message.
>>
>> My goal is to create purchase-orders written on unique files, and to
>> separate them my idea was to baptize files with the IP addresses, which
>> would ive each visitor an unique purchase-order...
>>
>> Any hints to a newbie?
>
> http://uk3.php.net/manual/en/reserved.variables.server.php
> 'REMOTE_ADDR'
>
> But don't rely on it to be the same each time for a customer. If they are on
> a shared connection then the ISP may give them a different IP each time they
> access the internet.
>
> --
> Lester Caine - G8HFL
> -----------------------------
> Contact - http://lsces.co.uk/wiki/?page=contact
> L.S.Caine Electronic Services - http://lsces.co.uk
> EnquirySolve - http://enquirysolve.com/
> Model Engineers Digital Workshop - http://medw.co.uk//
> Firebird - http://www.firebirdsql.org/index.php
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Can I get the IP address from a visitor?
am 01.12.2009 14:07:02 von olavell
Lars Kristiansson wrote:
[..]
> My goal is to create purchase-orders written on unique files, and to
> separate them my idea was to baptize files with the IP addresses, which
> would ive each visitor an unique purchase-order...
>
> Any hints to a newbie?
Yes. Do NOT use IP adresses as identifiers. Just forget about it.
People share connections, e.g. when they are in the same building or when
they are using the same proxy. People use domestic/consumer internet
connections that have dynamic IP addresses. Identifying people by their
IP address is therefore stupid.
If it is just to have a key to some data, you could try using a GUID. And
check when you generate one that it doesn't already exist (though the
chance is extremely small, it is not zero). Or just use some serial
number like everyone else does ;)
It may look boring to make files like order0001, order0002 etc. But it
works.
Any reason you are not storing your orders in a database?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Can I get the IP address from a visitor?
am 02.12.2009 08:57:42 von Ben
I happen to have grabbed this function from php.net a while back, and
have been using it since:
// by "fr600 at hotmail dot com" at http://us2.php.net/getenv
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);
}
though as others have pointed out, IP address is not a very good way to
uniquely identify visitors (at least not on its own).
Lars Kristiansson wrote:
> Hi!
>
> This is probably the wrong forum. Please redirect me if im out of place.
>
> I would like to find out what IP address my visitor uses when visiting a
> php script page on my domain. This page would contain a form in which
> the visitor would state his/her message.
>
> My goal is to create purchase-orders written on unique files, and to
> separate them my idea was to baptize files with the IP addresses, which
> would ive each visitor an unique purchase-order...
>
> Any hints to a newbie?
>
> Cheers, Lars
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Can I get the IP address from a visitor?
am 02.12.2009 17:58:01 von TedD
Hi:
My $0.02.
http://www.webbytedd.com/cccc/real-ip/
Open to suggestion/correction.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php