$username = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
if ($username == 'admin' && $password == 'secret') {
echo 'Authentication successful.';
} else {
header('WWW-Authenticate: Basic realm="Restricted Area"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authentication failed.';
exit;
}Basic Authentication
Related Posts
More content you might like
Tutorial
bash
How to Create SSL for a Website on Ubuntu
If you are using ufw (Uncomplicated Firewall), ensure HTTPS traffic is allowed:
sudo ufw allow 'Apache Full' # For Apache
sudo ufw allow 'Nginx Full' # For Nginx
sudo ufw enableOct 21, 2024
Read More Cheatsheet
VPN Services Cheat Sheet: Top Providers and Apps
- Key Features:
- 35,000+ servers in 78 countries.
- MACE ad-blocking feature.
- No-log policy.
- Supports torrenting.
- Split tunneling.
- Open-source apps.
- Pricing:
- $11.99/month (monthly plan).
- $3.33/month (1-year plan).
- $2.03/month (3-year plan).
- Supported Platforms:
- Windows, macOS, iOS, Android, Linux, browsers, routers.
- Key Features:
- No-log policy.
- Secure Core servers (extra security).
- P2P support.
- Integrated with ProtonMail.
- Free tier available.
- Works with streaming services.
- Pricing:
- Free plan available.
- $9.99/month (monthly plan).
- $5.99/month (1-year plan).
- $4.99/month (2-year plan).
- Supported Platforms:
- Windows, macOS, iOS, Android, Linux, routers.
Aug 21, 2024
Read More Code
javascript
Validate Password Strength
No preview available for this content.
Jan 26, 2024
Read More Code
javascript
Basic Authentication using 'express-basic-auth' middleware
No preview available for this content.
Jan 26, 2024
Read MoreDiscussion 0
Please sign in to join the discussion.
No comments yet. Be the first to share your thoughts!