How to Use Password Authentication

If want to restrict access to certain areas of your website to certain users, then you must format your site for authenticating passwords. Password authentication enables you to validate and verify the identity of an individual requesting access to a particular URL. This enables you to protect these restricted areas from hackers. Follow the steps below to set up a very basic function in PHP.

Instructions

    • 1

      Open a new blank document in Notepad or some other ASCII text editor.

    • 2

      Add the following code to the blank document:






      if (( $pwd == PASSWORD ) && ( $user == USERNAME )) //Set the Password and Username here -
      {
      $webpage = "http://www.YOURWEBSITE.com/php/index.htm/" ; //Chosen web page
      $fp = fopen( $webpage, "r" ) or die ("Couldn't open $webpage") ; //Open the page
      while ( ! feof( $fp ) ) //
      { print fgets( $fp, 1024 ) ; } //Display page in browser
      }
      else //If password or Username incorrect
      {
      echo "

      "; //Display and error message and
      echo "

      " ; //instructions
      echo "Authentication Failed

      Please hit your 'Back' button and try again.
      " ;
      echo "

      " ;
      }
      ?>




      PHP Menu Page | Home





    • 3

      Replace http://www.YOURWEBSITE.com/ on line 4 with the URL for your website.

    • 4

      Delete 'PASSWORD' and 'USERNAME' on line 11 and replace them with your choice of variables.

    • 5

      Change 'http://www.YOURWEBSITE.com/php/index.htm/' to match the URL of your website. Don't forget to include '/php/index.htm' after the domain name.

    • 6

      Save the document as "pwd.php" and upload it to your website.

    • 7

      Test the URL, user name and password to ensure proper password authentication.

Related Searches:

Comments

  • macman4ever Mar 02, 2008
    I DONT SEE ANY CODE HERE

You May Also Like

Related Ads

Featured