below is my PHP routine for using SESSION functionality. I have three webpage by name login.php, homepage.php,logout.php.
while I enter the correct password and username in my login.php page, it redirects me to homepage.php. In homepage.php, it contains a logout link. while I clicked that logout link, it redirects me to login.php. these fucntion work absolute as what I expect. but my problem now is while I open homepage.php alone, it should redirect me to login.php. but it opens the homepage.php. I need a exact condition for homepage.php to only open homepage.php while submitting correct data in login.php. otherwise while I open homepage.php directly, it should redirect me to login.php. but the main thing is I do not need to destroy session but I can empty my session value as 

> 
> $\_SESSION['sumthing'] == '';
> 
> 
> 

hope you understand my problem. thanks in advance.

**Login page**

```
<?php 
    include("includes/config.php");
    if ($_POST['frmSubmit']) {
        $strUserData = doSelectUserDetails($_POST);
        if($strUserData) {
            $_SESSION['SESS_UserId'] = $strUserData['user_id'];
            $_SESSION['SESS_UserName'] = $strUserData['user_name'];
            session_write_close();
            header('Location: homepage.php');
        } else {
            $strMessage = 'User Name or Password is Incorrect!';                                                                    
            $strClass = 'Error';
        }   
    }

?>

```

**Home page**

```
<?php
    include("includes/config.php");
    if((!isset($_SESSION['SESS_UserId'])) || (($_SESSION['SESS_UserId']) == '')) {
        header("location: login.php");
        exit;
    }
?>

```

**Logout**

```
<?php
        $_SESSION['SESS_UserName'] == '';
        $_SESSION['SESS_UserId'] == '';
        header("location: login.php");
        exit();
?>

```

**Function**

```
function doSelectUserDetails($objArray)
{
    $sqlSelect = "SELECT * FROM tbl_userdata WHERE user_name = '".$objArray['frmUserName']."' AND user_password = '".$objArray['frmPassword']."' ";
    $strValues = SelectQry($sqlSelect);
    return $strValues[0];
}

```