This topic is locked

Update field with $_SERVER['REMOTE_ADDR'];

3/3/2007 8:14:49 AM
PHPRunner General questions
L
Lisa2006 author

Hi Everyone,
Can you please help me.
I have the following created for test purposes:
Table: _demotable

field: username

field: password

field: ipaddress

field created by PHPrunner: ID
I have achieved the following: user logs in using there 'username' & 'password' and gets to see there username, password & ID in the "LIST PAGE"
At this point i want there IP Address to be logged in the 'ipaddress' field upon successful login.
I'm assuming that the coding needs to be entered in the Global Events > Login Page > After Successful Login
My problem is that I don't have any coding experience - and would appreciate anyone would could supply the code.
Thanks everyone in advance
Lisa <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=4740&image=1&table=forumtopics' class='bbc_emoticon' alt=':(' />

T
thesofa 3/4/2007

hI

I have made a few aSSUMPTIONS.

i HAVE ASSUMED THAT YOU WANT TO LOG EACH TIME SOMEONE USES THE DATABASE, by logging their logins?

I have changed the tables you made, see the file ipcollect.sql to use my system

do this

use navicat or phpmysql admin to load the file ipcollect.sql into mysql to make the tables.

here it is

make a database called `test`

save the code bit below to a file called `ipcollect.sql`

File ipcollect.sql

/*

MySQL Data Transfer

Source Host: 192.168.0.44

Source Database: test

Target Host: 192.168.0.44

Target Database: test

Date: 04/03/2007 19:39:01
SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------

-- Table structure for _demotable

-- ----------------------------

CREATE TABLE `_demotable` (

`ID` int(4) NOT NULL auto_increment,

`username` varchar(50) NOT NULL,

`password` varchar(50) NOT NULL,

PRIMARY KEY (`ID`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- ----------------------------

-- Table structure for _logins

-- ----------------------------

CREATE TABLE `_logins` (

`loginID` int(4) NOT NULL auto_increment,

`userID` int(4) NOT NULL,

`login_timestamp` datetime NOT NULL,

`IPaddress` varchar(35) default NULL,

PRIMARY KEY (`loginID`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- ----------------------------

-- Records

-- ----------------------------

INSERT INTO `_demotable` VALUES ('1', 'george', 'big');

INSERT INTO `_demotable` VALUES ('2', 'dad', 'sad');



end of file

use your mysql manager to upload the .sql file to the database server, this will create the tables and add a couple of users, george with a password of big and dad with a password of sad.
both files from this link

then use the file testip.phpr to access the data

on lines 13 and 25 you need to alter the values to suit your database setupr
}

L
Lisa2006 author 3/5/2007

Thank you for your response. I will try this at some point.
However, I'd seen a posting that advised the following.
I have inserted the code to Global Events > Login Page > After Successful Login
global $conn;

$ipaddress = $_SERVER["REMOTE_ADDR"];

$strSQLInsert = "insert into _sampletable (ipaddress) values ('$ipaddress')";

db_exec($strSQLInsert,$conn);
When i load the page and enter the username & password, i do not see the 'ipaddress' in the current record. Instead it populates the IPaddress into a new record.
Can you please help me. May be supply the code needed to insert the ipaddress into the currently logged in record.
Thank you all.

<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=15998&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' />

J
Jane 3/5/2007

Lisa,
to update added record use following code:

global $conn;

$ipaddress = $_SERVER["REMOTE_ADDR"];

$strUpdate = "update _sampletable set ipaddress='".$ipaddress."' where username='".$_SESSION["UserID"]."'";

db_exec($strUpdate,$conn);

L
Lisa2006 author 3/5/2007

Hi Jane,
Entered the code supplied and Work!!!
Your a STAR!!!!
Thank you <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=16004&image=1&table=forumreplies' class='bbc_emoticon' alt=':D' />