0

PROBLEM SOLVED. just one white space before session start made problem.....

Im using session for log in page.In index.php page i start session. Then i include login.html. After login i set session. but in index.php show $_SESSIon is empty. i tested many ways i font may be problem is session.save_path. how i can be sure?

    <?php session_start();?>
<html>
    <body>
<?php include_once("view/login.html");
       include_once("controller/login.php");
     echo $_SESSION['user']; ?>
</body>

</html>


    //login.html
    <form action="http://domain.com/index.php" method="post">
    <table>
    <tr>
        <td>
            Username : 
        </td>
        <td>
            <input type="text" name="txtUsername" />
        </td>
    </tr>
    <tr>
        <td>
            Password : 
        </td>
        <td>
            <input type="password" name="pwdPassword" />
        </td>
        </tr>
     </table>
    <input type="submit" name="btnLogin" value="Log In" />
    </form>

//login.php controler
    if(isset($_POST['btnLogin']))
        {
$_SESSION['user'] = "admin";
}
simra
  • 9
  • 2

1 Answers1

0

I think your flow is incorrect Do some thing like this:

index.php:

<?php
include_once("view/login.html");
include_once("controller/login.php");
if(isset($_SESSION['user']))
{
echo "User Is :".$_SESSION['user'];
}
?>

Login.html:

<form action="urltoindex.php" method="post">
<table>
<tr>
    <td>
        Username : 
    </td>
    <td>
        <input type="text" name="txtUsername" />
    </td>
</tr>
<tr>
    <td>
        Password : 
    </td>
    <td>
        <input type="password" name="pwdPassword" />
    </td>
    </tr>
 </table>
<input type="submit" name="btnLogin" value="Log In" />
</form>

login.php controller:

 <?php
    if(isset($_POST['btnLogin'])){
    $_SESSION['user'] = "admin";
    header("Location: urlToIndex.php");
    die();
    }
 ?>

index.php -> loginform -> submitform -> index.php(with User)

Anand Singh
  • 2,343
  • 1
  • 22
  • 34