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
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
}

?>

Link to comment
Share on other sites

    <?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]';

                       }

                    ?>

Link to comment
Share on other sites

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);

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.