Jump to content

[SOLVED] how to create a session log-in ???


gudfry

Recommended Posts

hi to all;

         

          I have a  PHP that keep the username and password for the user required to log-in the index page. but i have problrm problem with it.  here is a pice of code.

 

                            <?php

 

$user = 'xxxxxxxx';

$pass = 'xxxxxxxx';

 

    if (($_POST['username'] == $user) && ($_POST['password'] == $pass)) {   

     

        echo '<a href="page goes here">Clik here to view the site</a>';

       

    }

else {

      echo 'Wrong username and password.<br/>';

echo '<a href="index.html?menu=all">Go-back</a>';

}

?>

 

                    how woul i do this using session to keep the password and the username hidden. and also if the user is need to log-on the page before enter the index page.

 

thank for the advance.

 

     

         

         

Link to comment
https://forums.phpfreaks.com/topic/115769-solved-how-to-create-a-session-log-in/
Share on other sites

                             <?php

                  session_start();

                  $user = 'xxxxxxxx';
                  $pass = 'xxxxxxxx';

                            if (($_POST['username'] == $user) && ($_POST['password'] == $pass)) {   
                                   $_SESSION['loggedIn'] = 1;
                                   echo '<a href="page goes here">Clik here to view the site[/url]';
       
                            }
                            else {
                                   echo 'Wrong username and password.
';
                              echo '<a href="index.html?menu=all">Go-back[/url]';
                        }
                     ?>

 

And on the next page

 

<?php

session_start();

if ($_SESSION['loggedIn'] == 1)
{
// user is logged in
}

?>

    <?php

session_start();

                 $user = 'xxxxxxxx';

                 $pass = 'xxxxxxxx';

 

                           if (($_POST['username'] == $user) && ($_POST['password'] == $pass)) {  

    $_SESSION['islogin']=true;

                                  echo '<a href="page goes here">Clik here to view the site[/url]';

     

                           }

                           else {

                                  echo 'Wrong username and password.

';

                             echo '<a href="index.html?menu=all">Go-back[/url]';

                       }

                    ?>

thanks everyone.

     

            I do everything what evryone told me. but i have still problem with the session, because I still view my index page, and it doesnt require me to to log in. sory for my bad question

 

                I have this page to confirm password and the user name.

 

                session_start();

 

                  $user = 'xxxxxxx';

                  $pass = 'xxxxxxx';

 

                            if (($_POST['username'] == $user) && ($_POST['password'] == $pass)) { 

                                  $_SESSION['loggedIn'] = 1;

                                  echo '<a href="main_index.php">Clik here to view the site';

                            }

                            else {

                                  echo 'Wrong username and password.';

                                  echo '<a href="index.html?menu=all">Go-back';

                        }

 

              this is my another page which is my index

 

                <?php

 

session_start();

 

if ($_SESSION['loggedIn'] == 1)

{

// user is logged in

}

 

?>

 

 

  <?php

 

switch ($menu) {

case 'hotel': {

$includeFile='bodyhotel.php';

break;

}

default: {

$includeFile='bodycity.php';

break;

}

}

require_once($includeFile);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.