0

I am learning how to make login panel with session from here. I understood it fully, but I wanna open another file, in that code, when someone enter the right password + email, it only echo You have entered valid use name and password.

How to make it, clear everything on the page, and open a code (which I type)...

May be like, after I login, everything on the screen will get clear, and a image will open.

Termininja
  • 6,620
  • 12
  • 48
  • 49
KC Here
  • 33
  • 3
  • 1
    Look at `header()` in the manual `header('Location: another.php');` header does lots of other things as well, but look up header with the Location parameter – RiggsFolly Aug 13 '16 at 13:14
  • how to change the content in the same page? – KC Here Aug 13 '16 at 13:19
  • Then put out some different HTML if login was successful – RiggsFolly Aug 13 '16 at 13:21
  • how? what to write, instead of echo – KC Here Aug 13 '16 at 13:22
  • Maybe you should just complete the tutorial without modifying it. Likely as not they will cover that later in the tutorial – RiggsFolly Aug 13 '16 at 13:23
  • [This answer](http://stackoverflow.com/questions/4286677/show-image-using-file-get-contents) will show you how you can login and then output an image for, for example. You run your login script and once you've establish an authetic login then you can run the code exampled in the link. – Martin Aug 13 '16 at 17:04

2 Answers2

0

You can do this to the login function add a variable to check if this user is logged in or not

<?php
        $msg = '';
        $logedin = false;
        if (isset($_POST['login']) && !empty($_POST['username']) 
           && !empty($_POST['password'])) {

           if ($_POST['username'] == 'tutorialspoint' && 
              $_POST['password'] == '1234') {
              $_SESSION['valid'] = true;
              $_SESSION['timeout'] = time();
              $_SESSION['username'] = 'tutorialspoint';

              //echo 'You have entered valid use name and password';
              $logedin = true;
           }else {
                $logedin = false;
              $msg = 'Wrong username or password';
           }
        }
     ?>

then check if the user is logged in or not to see what you will show

 <div class = "container">
  //if the user is NOT logged in
    <? if($loggedin){ ?>
     <form class = "form-signin" role = "form" 
        action = "<?php echo htmlspecialchars($_SERVER['PHP_SELF']); 
        ?>" method = "post">
        <h4 class = "form-signin-heading"><?php echo $msg; ?></h4>
        <input type = "text" class = "form-control" 
           name = "username" placeholder = "username = tutorialspoint" 
           required autofocus></br>
        <input type = "password" class = "form-control"
           name = "password" placeholder = "password = 1234" required>
        <button class = "btn btn-lg btn-primary btn-block" type = "submit" 
           name = "login">Login</button>
     </form>

     Click here to clean <a href = "logout.php" tite = "Logout">Session.
     <? }else{ ?>
      // if user logged in yout code goes here
     <? } ?>
  </div> 
Beshoy Tamry
  • 75
  • 1
  • 11
-1

ya cool so simple, after echo line ie.'echo 'You have entered valid use name and password';', please use this or just replace the line

header('Location: http://www.example.com/');

you can use any link or local file at the place of this example link

rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156