Jump to content

Password Protecting HTML Pages with PHP


Akenatehm

Recommended Posts

Here are the basics.... you have not given us much to work with.

 

<?php

if(!isset($_SESSION['loggedIn']))  // check for a logged in session var
{
  header('Location:/login.php'); // if it is not found, then jump to the login page
}

?>

 

On login.php, create a form with a user name and password boxes in it.

 

login.php

<?php

if(isset($_POST['nameOfLoginButton']))
{
   // we are going to process the login....

   // initiate connection to the database

   // once we have a connection to the db.....
  $usernameField = $_POST['userName'];
  $encryptedPassword = md5($_POST['password']); // I assume your using the md5 hash function to store passwords in the db.
  
   $result = mysql_query("SELECT * FROM usersTable WHERE usernameField = '$userName' && password = '$encryptedPassword'");
  if(mysql_num_rows($result) > 0)
  {
      // a row was returned and our user entered valid credentials, so log them in
      $_SESSION['username'] = $usernameField;
      $_SESSION['loggedIn'] = true;
  }

}
?>

 

Make sure to have session_start() at the beginning of each page you wish to have protected. use the first if() statement on every page you want to password protect.

 

Let us know if you have questions... This is not intended for you to be a copy / paste solution... but to give you the basics. It should be beefed up to protect the variables and clean the sql query before running it.

 

Nate

Link to comment
Share on other sites

can the first little PHP script be inserted into an HTML page?

Yes but be sure to put session_start(); before anything else.

 

is there a way to decrypt with php so that the data can be read in a SWF Flash Login.

This kind of password set up is one way. Flash is be able to use php to make the password check.

Link to comment
Share on other sites

can the first little PHP script be inserted into an HTML page?

Yes but be sure to put session_start(); before anything else.

Could you explain how to do this a bit better please?

 

is there a way to decrypt with php so that the data can be read in a SWF Flash Login.

This kind of password set up is one way. Flash is be able to use php to make the password check.

Could you maybe state the other ways and/or explain how to do them please and how i would go about setting this up?

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.