Forgot Password / Register
Site Statistics
Total Members: 520
Total Tutorials: 242
Newsest User: 8884244477
Todays Unique Hits: 460
0 Users 5 Guests Online
Forum Index » PHP + MySQL » Wanted to get your users IP ?
Posted on Thursday 25th October 200 at 04:08 AM
Enros
templates/default/images/noavatar.png's Avatar
Newbie
Okay I didnt know how to post something on the PHP - User System part so I decided to post it here.

This can be used if your using the banning script or the warning script for the RMB user system aswell... (Thats how I used it but I didnt use there banning script)


Okay first you need to go into your phpmyadmin and add this to your members table.
<b>
name : ip
Type : text
Null : not null
</b>

And now we can start going into the IP part.
Go to the login.php file and find


//if it is continue
else
//if the db password and the logged in password are the same login
if ($udata[password] == $password)
{
$query = mysql_query("SELECT * FROM `members` WHERE `username` = '$username'") or die(mysql_error());
//fetchs the sql
$user = mysql_fetch_array($query);
$last_date = date("l, F j, Y h:i A");
$update = mysql_query("UPDATE `members` SET `last_seen` = '$last_date' WHERE `username` = '$user[username]' AND `id` = '$user[id]';") or die(mysql_error());
//sets the logged session
$_SESSION['id'] = "$user[id]";
$_SESSION['password'] = "$user[password]";
echo "<font color='black'><font size='1' face='Verdana'>You are now logged in, Please wait. . .";
//redirects them




And just below it put :

///////////////////////////// ip////////////////////
// get there ip address
$ip = $_SERVER['REMOTE_ADDR'];
// update there ip address in the database
mysql_query("UPDATE `members` SET `ip` = '$ip' WHERE `username` = '$user[username]' AND `id` = '$user[id]'") or die(mysql_error());
//////////////////////////// i stopp adding stuff her/////////////////////////



Okay so now youve got the ip adress when your user logs in.



But were do you want it displayed ? I put mine in the profile pages so MODs could look at them and bann the user if they wanted to.

So go to members.php and you can pretty much put this code anywere so you choose were it is displayed and who can see it.


if ($logged[userlevel] > 5)
{
echo "<br><b>IP:</b> $user[ip]";
}
else
{
echo "";
}
echo "</div>";

So lets go through what we just did.
We got the users IP from when they last logged in.

Then using this simple ifelse script were displaying it.

This part basically says if the logged user is greater then the user level of 5 then let them see the IP. the user level can be change and you can make it just == 6 if 6 is your admin level.

if ($logged[userlevel] > 5)
{

This big echo's the IP for the MOD/Administrator to see.
echo "<br><b>IP:</b> $user[ip]";

And the else script basicly says if the user is anything but this then you wont see it.


And there you go you now you have grabbed the ip and are able to display it for your MODS or Admins to bann or warn at will.
Posted on Thursday 25th October 200 at 05:34 AM
-=InSaNe=-
templates/default/images/noavatar.png's Avatar
Junior Member
Under the navigation it sais "Tutorials" click "Add Tutorial" then follow the steps and put it there, that way more people know about it rather then on forum :D
Posted on Sunday 4th November 2007 at 01:08 PM
Enros
templates/default/images/noavatar.png's Avatar
Newbie
meh