This topic has been closed for further discussion.
Administrator
From: Colorado, USA
Registered: 2006-02-15
Posts: 2427
I've been thanked 105 times.
Offline
I know you can get a visitors ip address and have it displayed on the page.
What I would like to do with our local community forum is to get the guest viewers ip address but only have it displayed for the admins and or moderators. Is this possible?
Attention designers and webmasters - "The Beauty of CSS"
Valid Web Designs tutorials on HTML, XHTML and CSS
Home Security Systems
Member
From: San Antonio, TX
Registered: 2006-08-07
Posts: 596
I've been thanked 34 times.
Offline
Sure, in php, you can get the ip address like this:
$ip=$_SERVER['REMOTE_ADDR'];
You should already have the "rank" of the person logged in, simply test whether they're an admin, and display $ip if they are.
Administrator
From: Colorado, USA
Registered: 2006-02-15
Posts: 2427
I've been thanked 105 times.
Offline
Thanks Steven,
I'm going to go play around with the placement of this and do some testing.
First question, Will this code display multiple ip's or will I need to do something else with it?
Second question, To display multiples how would I set it so that all the ip's don't run together as a single line?
Attention designers and webmasters - "The Beauty of CSS"
Valid Web Designs tutorials on HTML, XHTML and CSS
Home Security Systems
Member
From: San Antonio, TX
Registered: 2006-08-07
Posts: 596
I've been thanked 34 times.
Offline
Wait, are you trying to see the IP addresses of people logged on at other computers from your computer?
That bit of code just gets the IP address of the instance it's running in. It'll take a bit more to track the information from all of the instances.
Since the php is run on the server side, you'll have access to the info at your server using that code, but you'll probably need to store the IP addresses somewhere like in a mySQL table. Then when an admin or mod are logged in the program can read all the current IPs off of the table individually and display them how you want.
Cleaning up after they leave might be a trick though. I think your best bet is using sessions. I haven't messed with sessions yet, so I can't be much help there. Maybe this will help.
Administrator
From: Colorado, USA
Registered: 2006-02-15
Posts: 2427
I've been thanked 105 times.
Offline
Yup, that is what I was wanting to do. In playing around and searching G getting more and more refined in my search. I have learned that it would need to be stored. Not good. I have played with sessions and have also learned to stay away from them unless it is really needed. Bad mojo for seo.
Ah well, for now I will have the page display their address, watch things, see what happens.
Attention designers and webmasters - "The Beauty of CSS"
Valid Web Designs tutorials on HTML, XHTML and CSS
Home Security Systems
Administrator
From: Yorkshire, UK
Registered: 2006-08-19
Posts: 3166
I've been thanked 101 times.
Offline
I currently do this on some of my applications.
It involves tying together the two concepts - sessions and databases. In php you can use a database to store the session information. It's a really simple table with the session id, session data and expiry time
using session_set_save_handler your session keeps track of all the sessions and does the garbage clean up for you.
You then perform another, non-session related, query on the table; parsing each row and extracting the ip address
To set the ip in the session you might do
$_SESSION['IP'] = $_SERVER['REMOTE_ADDR'];
I use one of the user-contributed solutions on the page linked to above (here - http://uk3.php.net/manual/en/function.s … .php#60316).
I really like using a server side database to store the session data in as all the client's user agent has to worry about is the session id.
You may want to read up about session fixation and php's way round it - session_regenerate_id([bool $delete_old_session]). I set this to true. the session is 'copied' to a new id but can screw up when you're using ajax.
| Never |


