hello, i am using the following code to write an ip and date to a database

require_once "configgy.php";

mysql_query("INSERT INTO lastlogin(VisIP, VisDate) VALUES(\"".$HTTP_SERVER_VARS['REMOTE_ADDR']."\",  NOW(),");

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?

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:

create table if not exists 'lastlogin' (
'id' int(11) not null auto_increment,
'VisIP' varchar(15),
'VisDate' timestamp(14) not null,
primary key ('id')
)

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.

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.

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.

and how to have it clear the DB and rewrite?

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...

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.