Forum Sondria46®   →   Sondria46_Blog   →   Blog_Articles   →   Password Protection in PHP

Password Protection in PHP

Started by admin Nov 06th, 2024 at 10:32
admin
Admin
Posts: 95
Nov 06th, 2024 at 10:32

If you're building with PHP, you can also add basic authentication directly in your script:

<?php
$valid_username = 'username';
$valid_password = 'password';

if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) ||
    $_SERVER['PHP_AUTH_USER'] != $valid_username || $_SERVER['PHP_AUTH_PW'] != $valid_password) {
    header('WWW-Authenticate: Basic realm="Restricted Area"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Access denied';
    exit;
}
?>
<!-- Protected content goes here -->

Replace username and password with your credentials.

 



Home   •   FAQ   •   Support   •   Terms of Service   •   Privacy   •   News   •   Forum
Copyright © 2024 Sondria46®. All Rights Reserved.
Powered by EvolutionScript Version 6.6