Jump to content

Lock the session to a specific IP address


aj123cd

Recommended Posts

Can I Lock the session to a specific IP address?

 

If(isset($_SESSION[‘last_ip’] )) == false) {
$_SESSION[‘last_ip’] =$_SESSION[‘REMOT_ADDR’];
}
if($_SESSION[‘last_ip’] != =$_SESSION[‘REMOT_ADDR’]){
session_unset();
session_destroy();
}

thank you in advance

 

That's the problem with using IP addresses to keep track of user information. IP addresses can change for a number of reasons. Using IP addresses to store unique user information isn't reliable. The best way to keep track of individual user stuff is to have login functionality.

 

You could use IP information as an added layer of security.

 

First you need to find the IP address. $_SERVER["REMOTE_ADDR"] isn't always the most reliable. There are some great functions out there, just google for 'php find ip address' or something like that.

 

Best way to store that info is on a database on your server in a field like 'LastIP' and then compare current with last IP and else: send them back to login page.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.