简体   繁体   中英

How to find IP address just with session IDs?

Actually it's a simple question but I couldn't asked the correct question to google maybe. Here is the problem:

Think that I have a website to which clients connect. I store session IDs (ie sbf1qql1qikvr4vnsvbomr1d61) for each connected client and I want to retrieve IP adresses using these session IDs. I'm running a php code

root@34s:~# php checkSessions.php

on the server machine. And checkSessions.php has a code similiar to the following snipplet

//Enter an infinite loop
while(1)
{
            //Get session ids and user ids from the database 
    $q1 = $db->getQ("SELECT user_id, session_id, FROM all_sessions");
    foreach($q1 as $q)
    {
        if($q[0]==63)
        {
                         // Now, I need to get IP adress. I only have a session id
        }
    }

           // Wait 2 seconds and do the same procedure again 
       sleep(2);
}

So, could you provide any method to find out the IP adress of the client using this session ID.

Sessions do not store IP addresses or any other extra information. You need to add it to the session when it is started. ie:

session_start();
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM