943,754 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2699
  • PHP RSS
Jun 1st, 2006
0

Show Last IP

Expand Post »
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?
Similar Threads
Reputation Points: 11
Solved Threads: 0
Light Poster
bobby9101 is offline Offline
46 posts
since Jun 2005
Jun 1st, 2006
0

Re: Show Last IP

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:
PHP Syntax (Toggle Plain Text)
  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.
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005
Jun 2nd, 2006
0

Re: Show Last IP

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.
Reputation Points: 11
Solved Threads: 0
Light Poster
bobby9101 is offline Offline
46 posts
since Jun 2005
Jun 2nd, 2006
0

Re: Show Last IP

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.
Reputation Points: 10
Solved Threads: 1
Light Poster
BlazingWolf is offline Offline
32 posts
since Feb 2006
Jun 2nd, 2006
0

Re: Show Last IP

and how to have it clear the DB and rewrite?
Reputation Points: 11
Solved Threads: 0
Light Poster
bobby9101 is offline Offline
46 posts
since Jun 2005
Jun 2nd, 2006
0

Re: Show Last IP

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...
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005
Jun 5th, 2006
0

Re: Show Last IP

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
Reputation Points: 11
Solved Threads: 0
Light Poster
bobby9101 is offline Offline
46 posts
since Jun 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Help, If You Can Find My Error! Exhausted Again
Next Thread in PHP Forum Timeline: Please If You Can See Where My Mistake Is!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC