<?php
    if ($_POST)                                           #if 2nd or subsequent time
    {                                           
        validate();                                       #validate entry of user & pswd        

        if (! $msg)                                       #if no error
        {
//          ini_set('session.use_trans_sid', true);       #in case it is not set in the php.ini file
            session_start();                              #start a session
            $_SESSION[name]       = $name;                #save name in session
            $_SESSION[start_time] = time();               #save start time in session
            $_SESSION[counter]    = 0;                    #start a counter                  

            if (SID)                                      #must be using URL rewrite
                $sid = "?". SID;                          #append ? and the SID         

            $url = "session_use.php" . $sid;              #append the session id at end of URL (if any)             
            header("Location: $url");                     #redirect to session_use.php                                                                
        }                                                 #Remember: in header this must manually done  
    }                                                     

    display(); 
?>


<?php

//=============================================================================
// Validate all required input fields
//=============================================================================
    function validate()
    {
        global $name, $msg;   

        $name = $_POST['name'];                         #get HTML form entry fields 

        if (! $name) 
            $msg  = 'Please enter your name!';     
    }

//=============================================================================
// Display the form
//=============================================================================
    function display()
    {
        global $name, $msg;   
?>
        <html>
        <body bgcolor=lightyellow>
        <h1>Start a  Session</h1>
        <br>
        <form method=POST action=session_start.php >
        Enter Your Name <input type=text name=name value=<?php echo $name?> >
        <br><br>
        <input type=submit value="   Login   ">
        </form>
        <div style="color:red;"> <?php print $msg?>   </div>
<?php
    }

//=============================================================================
?>

<?php include "../include.php"; ?>              <!-- hyperlink to see the code -->
</body>
</html>