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

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.