Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Login track and overwrite IP

8:24 am on Aug 22, 2008 (gmt 0)

5+ Year Member

Ok so what I want to do, is when a person logs into the site, it tracks their IP, and overwrites their old one that was on the previous time they logged in, just incase they change IP addresses or whatever. Here is what I have so far:


mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());

mysql_query("UPDATE $table SET currentIP = $ip WHERE $userid = $_COOKIE['userid']");

And this code isn't seeming to work :/ Any ideas?

8:35 am on Aug 22, 2008 (gmt 0)

5+ Year Member

Shouldn't this: WHERE $userid = $_COOKIE['userid']
be: WHERE userid = $_COOKIE['userid']
10:27 pm on Aug 22, 2008 (gmt 0)

5+ Year Member

$_COOKIE['userid'] you are calling your self into trouble. you should escape cookies before you use it.

you can only use array in a quotation marks if you use {} braces/brackets. but that is not even good considering performance, it increases the time that php to parse the string.

here is the solution
mysql_query("UPDATE $table SET currentIP = $ip WHERE userid =". $_COOKIE['userid']."");

hope that helps you.

[edited by: Mohamed at 10:28 pm (utc) on Aug. 22, 2008]

10:32 pm on Aug 22, 2008 (gmt 0)

5+ Year Member

Well would it still work since, it's setting the cookie (userid) when I login, but the update IP is calling the cookie after I set it, would it still work?
11:11 pm on Aug 22, 2008 (gmt 0)

5+ Year Member

If I understood you correctly. yes it will work. since you can access cookies just after you set it.

[edited by: Mohamed at 11:12 pm (utc) on Aug. 22, 2008]

2:52 am on Aug 23, 2008 (gmt 0)

5+ Year Member

Ok cool I'll try it out

Featured Threads

Hot Threads This Week

Hot Threads This Month