Question: From the following data i want to get the MaxID of EmpID 1100

```
ID  | EmpId  
1   | 1002   
5   | 1100   
6   | 1109   
7   | 1100   
9   | 1100   
10  | 1250   
11  | 1250   
12  | 1100   

```

Results should be

```
ID
9  

```

Please help

Answer: 
You can store url inside a session may, $\_SESSION['visited\_page'] inside header. Every time user visit different url this session value updated. During logout, you can assign url inside $\_SESSION['visited\_page'] to $\_SESSION['last\_visited'] and unset $\_SESSION['visited\_page']. Now you have the url user last visit. I hope you get my point.
You should first get user refer page in a variable using $\_SERVER['HTTP\_REFERER']; in your login page.

LIKE:

```
<?php 
    session_start();
    $refPage = $_SERVER['HTTP_REFERER']; 
?>

```

And now when the user clicks to Login then change header location to user refer page

LIKE:

```
<?php 
if(isset($_POST[login])){
    session_start();
    header('location:' . $refPage);
}
?>

```

And in this time you should first check that user refers page empty or not because your user can visit direct your login page then your $refPage variable will be empty so after Click to Login page stays here

LIKE:

```
<?php
if(isset($_POST[login])){
    session_start();
    $refPage = $_SERVER['HTTP_REFERER'];  // get reffer page url
    if(empty($refPage)){ 
        header('location: yourredirectpage'); // if ref page is empty then set default redirect page.
    }else{
        header('location:' . $refPage); // or if ref page in not empty then redirect page to reffer page
    }
}
?>

```

Or you can use input type hidden where you can set value $\_SERVER['HTTP\_REFERER'];

LIKE:

">
And when a user clicks to Login then you can get the refPage value and redirect the previous page. And you should also check empty refer page. Because your user can visit direct your login page.

Thank you.