Question

I have a login page where the user has to provide his/her credentials and then log in to the page named dashboard.php.

Now the credential validation is done on this page.I used $_POST to pass the variables. If user credentials are not correct then he is taken back to index.php. Else the page is filled with user data from the db.

Now the problem is that when user revists dashboard.php from any other page (other than index.php) How do I get the same credentials back so as to show the contents related to the user? I tried using session variables by saving the credentials in them but still not working.

I have added a sample code of what I have done:

index.php

<html>
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <form action="dashboard.php" method="post">
        <input type="text" name="txt">
        <input type="submit">
    </form>
</body>

this travels to dashboard.php which is:

<?php
    session_start();
   if(isset($_SESSION['LOG_IN'])!=1)
{

    $xt = $_POST['txt'];
    $_SESSION['LOG_IN']=1;

}

?>

<html>
    <head>

    </head>
    <body>
        <p> HI </p>
        <a href="3.php"><?php $xt ?>Link of 3.php</a>

    </body>
</html>

and now when i go to some page called 3.php and press the back button. I get the form re-submission page.

No correct solution

OTHER TIPS

First start session_start(); and pass its value $_SESSION['var_name']; and on other (dashboard) page check $_SESSION['var_name'] is set or not ?

you can check this DEMO

To make SESSION work on every page you must use session_start(); on each page at the top of page.

Then you can easily access session using print_r($_SESSION);

You should refer to PHP Session Documentation for more info.

You should use session_start(); at top of page. See your question I have updated it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top