This topic is locked

Fill field who depend on stored IP

7/23/2012 12:21:27 PM
PHPRunner General questions
W
wundebar author

Hi at all!

I would like to know if is possible automatically fill a field who depend on a stored ip, with a name.

For example i have two fields, one (IP) who is filled any time with $_SERVER['REMOTE_ADDR'] as default value, and another one who is called "proprietario" and who contains names of persons. For each name there is an ip, and i would that the field proprietario is automatically filled with the corresponding IP.

I've read that could be used $_SESSION but my database don't have any kind of log in session, so for me is important to know if i can do it also without a session who stores data.

It is possible? If it is possible, can someone show me some example?
Thank you! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=19878&image=1&table=forumtopics' class='bbc_emoticon' alt=':)' />

Sergey Kornilov admin 7/24/2012

Not sure if I understood this question right but $_SESSION variables will work even if you don't have a login page.

W
wundebar author 7/25/2012

Hi admin, i'm a newbie and i was sure it was not possible.

So can someone explain it to me with some example?

I wrote $_SESSION["UserID"] into the field "edit as" like a default value, but nothing happen. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=67155&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' />

Thanks

W
wundebar author 7/27/2012



Hi admin, i'm a newbie and i was sure it was not possible.

So can someone explain it to me with some example?

I wrote $_SESSION["UserID"] into the field "edit as" like a default value, but nothing happen. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=67175&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' />

Thanks


Hi to everybody.

Some solution?

With $_SESSION["UserID"] as default value, it returns to me something like: "t32thkm39ut7pk9k1fm19m1mo2" how can i change this with a name?

I also noticed that every time that i close firefox and then i open it again, the string changes again.

So my question is: how can i change that result into a name and get always the same name even if i close the web browser and then re-open it?

Thanks in advance.

W
wundebar author 7/31/2012



Hi to everybody.

Some solution?

With $_SESSION["UserID"] as default value, it returns to me something like: "t32thkm39ut7pk9k1fm19m1mo2" how can i change this with a name?

I also noticed that every time that i close firefox and then i open it again, the string changes again.

So my question is: how can i change that result into a name and get always the same name even if i close the web browser and then re-open it?

Thanks in advance.


Some idea?

Thank u in advance.

Sergey Kornilov admin 8/1/2012

I guess you need to provide more info on this.
If you don't have a login page - how wold you know the name of the current user?

W
wundebar author 8/22/2012



I guess you need to provide more info on this.
If you don't have a login page - how wold you know the name of the current user?


Hi admin.
I dunno,i was asking you, i was sure it was possible just storing IP information, but maybe i was wrong...?

Thank you

C
copper21 8/22/2012

I think I understand your question. You have a table containing 2 fields; one that has ip addresses and one that has names. Each ip address has a corresponding name. If you are getting a valid ip address using $_SERVER['REMOTE_ADDR'], and from that you would like to lookup on your table the name associated with that IP address. If $_SERVER['REMOTE_ADDR'] works like a session variable, not sure if it does, then you can get this a couple of ways. If you are on the add or edit page, you can use the events to do this. GO to add/edit event, "Process record values" and use this query:
$rs = CustomQuery("SELECT FROM YOUR_TABLE_NAME WHERE ip ='".$_SERVER['REMOTE_ADDR']."'");

$record = db_fetch_array($rs);
$values['field_on_add_or_edit_page_you_want_name_inserted_into'] = $record['name'];
OR use php snippet on the page you want to add the name and enter:
global $conn;

$strSQLSelect = "SELECT
FROM YOUR_TABLE_NAME WHERE ip = '".$_SERVER['REMOTE_ADDR']."'";

$rsSelect = db_query($strSQLSelect,$conn);

$data=db_fetch_array($rsSelect);
echo $data['name'];
Like I mentioned earlier, if you can use $_SERVER['REMOTE_ADDR'] as a session variable, that might work.
Let me know if that helps.
Brian