dean7 Posted May 8, 2009 Share Posted May 8, 2009 Hi, Ive got a website witch you need to reigster to get into the main website but i want to be able to see there ip's once there signed up, but how would i make it? Ive got this for register.php but not sure if it ther file i need to put it on. register.php: ><?php ob_start(); // allows you to use cookies include("config.php"); //gets the config page if ($_POST[register]) { // the above line checks to see if the html form has been submitted $username = $_POST[username]; $password = $_POST[pass]; $cpassword = $_POST[cpass]; $email = $_POST[emai1]; //the above lines set variables with the user submitted information if($username==NULL|$password==NULL|$cpassword==NULL|$email==NULL) { //checks to make sure no fields were left blank echo "A field was left blank."; }else{ //none were left blank! We continue... if($password != $cpassword) { // the passwords are not the same! echo "Passwords do not match"; }else{ // the passwords are the same! we continue... $password = md5($password); // encrypts the password $checkname = mysql_query("SELECT username FROM users WHERE username='$username'"); $checkname= mysql_num_rows($checkname); $checkemail = mysql_query("SELECT email FROM users WHERE email='$email'"); $checkemail = mysql_num_rows($checkemail); if ($checkemail>0|$checkname>0) { // oops...someone has already registered with that username or email! echo "The username or email is already in use"; }else{ // noone is using that email or username! We continue... $username = htmlspecialchars($username); $password = htmlspecialchars($password); $email = htmlspecialchars($email); // the above lines make it so that there is no html in the user submitted information. //Everything seems good, lets insert. $query = mysql_query("INSERT INTO users (username, password, email) VALUES('$username','$password','$email')"); // inserts the information into the database. echo "You have successfully registered!"; } } } } else { // the form has not been submitted...so now we display it. echo (" <center> <form method=\"POST\"> Username: <input type=\"text\" size=\"15\" maxlength=\"25\" name=\"username\"><br /> Password: <input type=\"password\" size=\"15\" maxlength=\"25\" name=\"pass\"><br /> Confirm Password: <input type=\"password\" size=\"15\" maxlength=\"25\" name=\"cpass\"><br /> Email: <input type=\"text\" size=\"15\" maxlength=\"25\" name=\"emai1\"><br /> <input name=\"register\" type=\"submit\" value=\"Register\"> </form> </center> "); } ?> Thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/157378-tracking-ips/ Share on other sites More sharing options...
premiso Posted May 8, 2009 Share Posted May 8, 2009 $ip = $_SERVER['REMOTE_ADDR']; //Everything seems good, lets insert. $query = mysql_query("INSERT INTO users (username, password, email, ip) VALUES('$username','$password','$email', '$ip')"); You will have to add ip to the column as a varchar(15) for that to work, but that should get you rolling. Just a note you may have to update their IP each time they login as it can and will change (unless they have a static which is rare). EDIT: Changed to varchar of 15 Quote Link to comment https://forums.phpfreaks.com/topic/157378-tracking-ips/#findComment-829608 Share on other sites More sharing options...
Maq Posted May 8, 2009 Share Posted May 8, 2009 You can add this hidden field: Quote Link to comment https://forums.phpfreaks.com/topic/157378-tracking-ips/#findComment-829609 Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 $username = htmlspecialchars($username); $password = htmlspecialchars($password); $email = htmlspecialchars($email); Instead of htmlspecialchars, please use mysql_real_escape_string. You should also hash the password with one of md5 or sha1. If you want to see the user's IP address, you can store that in the database. You can get it via $ip = getenv('REMOTE_ADDR'); or $ip = $_SERVER['REMOTE_ADDR']; Quote Link to comment https://forums.phpfreaks.com/topic/157378-tracking-ips/#findComment-829611 Share on other sites More sharing options...
dean7 Posted May 8, 2009 Author Share Posted May 8, 2009 Ty the when the register it says the ip. How would you do it so it would change when there ip changes? Quote Link to comment https://forums.phpfreaks.com/topic/157378-tracking-ips/#findComment-829615 Share on other sites More sharing options...
Ken2k7 Posted May 9, 2009 Share Posted May 9, 2009 You would run a check for their IP address when they log in. Compare it to the one in the DB and if they're not equal, update the DB. Quote Link to comment https://forums.phpfreaks.com/topic/157378-tracking-ips/#findComment-830146 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.