View Full Version : Ip
auriaks
10-15-2009, 09:36 PM
how i can detect visitors IP?? i have sessions script if needed.
thetestingsite
10-15-2009, 10:31 PM
The following PHP snippet displays the IP address of the visitor to the page.
<?php
echo $_SERVER['REMOTE_ADDR'];
?>
auriaks
10-16-2009, 06:49 PM
but what if i want to save ip on sql?? maybe i need to save it when they registering? thanks
$userIP = $_SERVER['REMOTE_ADDR'];
// adjust SQL to suit your table/other values
// use UPDATE instead if you're updating existing rows
$IPsql = mysql_real_escape_string("INSERT INTO userIPaddr (userIP) values ('$userIP')");
//assumes you have already connected to your DB
mysql_query($IPsql);
however, note that even under normal circumstances, many users may not have the same IP every time they connect - so using the IP to validate something (if that's what you're trying to do) won't always work.
Schmoopy
10-17-2009, 10:01 AM
That's true, especially with networks, where there are many people connected, whose information is all passed as one IP by the router, so if you have one person in that network whose paid for a service, and you allow them access, it could mean that everyone else on that network could get through too.
It would also work the other way round, where someone might be blocked, and then it block everyone on the network, which may cause more problems.
auriaks
10-21-2009, 03:02 PM
I don't want to create IP ban or smth... thanks for warnings :D TRAQ, all lines i have to write after connection script?? and what variables i have to create in the db->table to fit your written script? Many thanks..
what database columns? In my example above, I used the column name "userIP". You could name it anything you wanted.
auriaks
10-21-2009, 08:06 PM
It works... thx :D Can you take a look to this Q?? Question for rewriting script (http://www.dynamicdrive.com/forums/showthread.php?t=49358)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.