/    Sign up×
Community /Pin to ProfileBookmark

Get user’s I.P. Adress

Can somebody provide me with the code needed to get a visitors
ip adress and store it as a variable?

i am programming a voting script for my site and i want to append
the voters ip address to a text file to prevent multiple votes
from the same ip address.

so when they vote it will see if their ip address is already in the log
and prevent them from voting more than once unless they change
their i.p.

it is just a hobby site so it doesn’t have to be completely airtight
with regards to voting accuracy.

i know how to keep track of the ip’s and that other stuff, i just
need to know how i can get the visitors ip so i can pass it to
the voting script to test it before registering a new vote.

thanks a bunch,
bsmbahamas.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@pcthugDec 28.2006 — The client's IP address is stored within the REMOTE_ADDR SERVER superglobal variable.
[code=php]$ip = $_SERVER['REMOTE_ADDR'];[/code]
Copy linkTweet thisAlerts:
@bsmbahamasauthorDec 28.2006 — The client's IP address is stored within the REMOTE_ADDR SERVER superglobal variable.
[code=php]$ip = $_SERVER['REMOTE_ADDR'];[/code][/QUOTE]



thanks pcthug that works perfectly!
Copy linkTweet thisAlerts:
@felgallDec 28.2006 — Of course an IP address doesn't necessarily identify a unique visitor since the same person can have a different IP address at different times and an IP address can be assigned to different people at different times.
Copy linkTweet thisAlerts:
@NightShift58Dec 28.2006 — The alternative would be to use cookies and/or sessions but then somehow would come along and rightly claim that these, too, wouldn't guarantee anything as anyone bent on bypassing the basic safety measures could do so.

I think that for a voting script, using the IP is probably sufficient. Most users cannot manipulate that and, unless the voting is tied to a major jackpot, I would let it go at that...
Copy linkTweet thisAlerts:
@bsmbahamasauthorDec 29.2006 — The alternative would be to use cookies and/or sessions but then somehow would come along and rightly claim that these, too, wouldn't guarantee anything as anyone bent on bypassing the basic safety measures could do so.

I think that for a voting script, using the IP is probably sufficient. Most users cannot manipulate that and, unless the voting is tied to a major jackpot, I would let it go at that...[/QUOTE]


The i.p. approach would be sufficient for my purposes since it is only to

vote for sites/products/services that you like. ideally i would use a combination of username + password + email + i.p. address + time, but this script i'm creating is for public use and won't require users to register - it simply a directory of websites/products/services and any visitor can click a button to add a vote and optionally leave a comment that can be read by others.

if it were a prize involved then i'd make it more airtight and i know that the average user does not know how to manipulate their i.p. address, and i can always require registration for voting later on if it gets abused somehow.

thanks a bunch guys
×

Success!

Help @bsmbahamas spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...