Show Last IP

Reply

Join Date: Jun 2005
Posts: 46
Reputation: bobby9101 is an unknown quantity at this point 
Solved Threads: 0
bobby9101 bobby9101 is offline Offline
Light Poster

Show Last IP

 
0
  #1
Jun 1st, 2006
hello, i am using the following code to write an ip and date to a database
[php]require_once "configgy.php";

mysql_query("INSERT INTO lastlogin(VisIP, VisDate) VALUES(\"".$HTTP_SERVER_VARS['REMOTE_ADDR']."\", NOW(),");
[/php]
I would like to call this script in another file, and everytime the script is called, have the new ip written in.
liek it is in CPANEL (log into cpanel and look at the top left, it says last log in from 127.0.0.1 or w/e your ip is)
how can i do this?
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,082
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: Show Last IP

 
0
  #2
Jun 1st, 2006
Just include the code you have above in the script you need IPs logged for.
Make sure you create a table in the database the script has access to. Eg:
  1. create table if not exists 'lastlogin' (
  2. 'id' int(11) not null auto_increment,
  3. 'VisIP' varchar(15),
  4. 'VisDate' timestamp(14) not null,
  5. primary key ('id')
  6. )

If the target script already connects to a database, and has its own database class, then you should use the target scripts database class instead of including configgy.php.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 46
Reputation: bobby9101 is an unknown quantity at this point 
Solved Threads: 0
bobby9101 bobby9101 is offline Offline
Light Poster

Re: Show Last IP

 
0
  #3
Jun 2nd, 2006
I have the database...
OK lemme explain this better, I have an Admin panel.
I would like to show the IP of the last person to log in.
So i would need for everytime the script was aactivated it would write the ip to the DB and clear the old one. however it would be better if it only wrote the ip on login, instead of everytime it was accessed.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 32
Reputation: BlazingWolf is an unknown quantity at this point 
Solved Threads: 1
BlazingWolf BlazingWolf is offline Offline
Light Poster

Re: Show Last IP

 
0
  #4
Jun 2nd, 2006
Include that part in the code that is excuted when the user has authenticated successfully, that would ensure you only did it once per session.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 46
Reputation: bobby9101 is an unknown quantity at this point 
Solved Threads: 0
bobby9101 bobby9101 is offline Offline
Light Poster

Re: Show Last IP

 
0
  #5
Jun 2nd, 2006
and how to have it clear the DB and rewrite?
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,082
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: Show Last IP

 
0
  #6
Jun 2nd, 2006
You'll have to look at some mysql resources to get a better Idea with working with mysql.

What you could do is delete the entry in mysql each time you update a new entry.
Like blazing_wolf said, include the code after the user has been authenticated successfully.

If you're just writing one IP, you'd better o f just write it to a file.
Use fopen('filename.txt', 'w');
That would clear the file each write...
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 46
Reputation: bobby9101 is an unknown quantity at this point 
Solved Threads: 0
bobby9101 bobby9101 is offline Offline
Light Poster

Re: Show Last IP

 
0
  #7
Jun 5th, 2006
thanks guys, (and gals )
I shall try that...
if anyone has a mysql way then post it cuz i would rather not use a flat file but w/e
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC