homepage Welcome to WebmasterWorld Guest from 54.226.21.57
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Login track and overwrite IP
tr8er8

5+ Year Member



 
Msg#: 3728702 posted 8:24 am on Aug 22, 2008 (gmt 0)

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:


$ip=$_SERVER['REMOTE_ADDR'];

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?

 

deMorte

5+ Year Member



 
Msg#: 3728702 posted 8:35 am on Aug 22, 2008 (gmt 0)

Shouldn't this: WHERE $userid = $_COOKIE['userid']
be: WHERE userid = $_COOKIE['userid']

Mohamed

5+ Year Member



 
Msg#: 3728702 posted 10:27 pm on Aug 22, 2008 (gmt 0)

$_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]

tr8er8

5+ Year Member



 
Msg#: 3728702 posted 10:32 pm on Aug 22, 2008 (gmt 0)

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?

Mohamed

5+ Year Member



 
Msg#: 3728702 posted 11:11 pm on Aug 22, 2008 (gmt 0)

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]

tr8er8

5+ Year Member



 
Msg#: 3728702 posted 2:52 am on Aug 23, 2008 (gmt 0)

Ok cool I'll try it out

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved