Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/157378-tracking-ips/
Share on other sites

$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

Link to comment
https://forums.phpfreaks.com/topic/157378-tracking-ips/#findComment-829608
Share on other sites

$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'];

Link to comment
https://forums.phpfreaks.com/topic/157378-tracking-ips/#findComment-829611
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.