I have this much, $ip = $_SERVER['REMOTE_ADDR']; PHP: But how do I store the IP of someone who submits a form and keep it in the database?
Yes, but I really don't know how to store a variable. I'm not good at PHP, just editing something that was already coded for me. Please post the example, thanks.
Here you go... hope this helps. require_once ("DB.php"); $ip = $_SERVER['REMOTE_ADDR']; $vals = array("field_name", $ip) // Change field_name to what is in your table $DATABASE = "db_name"; $USER = "user_name"; $PASSWORD = "pass"; $SERVER = "host_name"; $dsn = mysql://$USER:$PASSWORD@$SERVER/$DATABASE"; $dbconn =& DB::Connect($dsn, array()); $prepare = $dbconn->prepare("INSERT INTO table_name VALUES (?, ?)"); $result = $dbconn->execute($prepare, $vals); $dbconn->disconnect(); PHP: I use the DB class so if you do not have this installed I am sorry... I ahve not tested this so maybe soneone could check my coding, but I beleive I have it about right.
What are yo trying to accomplish with the script? Are you looking to track visitors, or just keep a lost of IP addresses that visit your site? Here is a very light non-PEAR version of the same script. I know that some servers dont have PEAR installed by default. //Mysql Variables $host = 'localhost'; $user = ''; $pass = ''; $db = 'ipTrack'; $table = 'records'; //connect to DB mysql_connect($host,$user,$pass) or die(mysql_error()); //get remote IP $ip = $_SERVER['REMOTE_ADDR']; mysql_query("INSERT INTO $table VALUES ('', '$ip', NOW())"); PHP: Here's a sql script for creating the table in the database: CREATE TABLE records ( id int(11) NOT NULL auto_increment, ip varchar(20) NOT NULL default '', date datetime, PRIMARY KEY (id) ) TYPE=MyISAM; Code (markup):