This is a discussion on HTTP Authentication within the Programming Articles forums, part of the Webmaster Articles/Tutorials category; Have you ever wanted a log in system for your site, to protect your admin cp, or to protect an ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| | #1 (permalink) |
| Cool Newbie | Have you ever wanted a log in system for your site, to protect your admin cp, or to protect an important file? With php, and a little feature in apache, you can easily do this using "HTTP Authentication." Let's get started by defining the username and password for the page. PHP Code: PHP Code: Here is what the log in box will look like in IE6: ![]() And in FireFox 1.0: ![]() Hopefully, your website is a lot more secure now. Tim |
| | |
| | #3 (permalink) |
| WMT Addict | tim when i add this to index.php PHP Code: |
| | |
| | #4 (permalink) | |
| Moderator | Quote:
Have i done something wrong? Code: <html>
<head>
<title></title>
</head>
<body bgcolor="#FFFFFF">
<?php
$username = "admin";
$password = "admin";
if (($PHP_AUTH_USER !== $username) || ($PHP_AUTH_PW !== $password))
{
header('WWW-Authenticate: Basic realm="Protected Area"');
header('HTTP/1.0 401 Unauthorized');
die("You do not have access to this file.");
}
?>
</body>
</html>
It could be that i am doing it incorrectly by the PHP version, do i need 4.x or 5.x?
__________________ Free .org domain - Click for details! Do not pm asking for things. My inbox is full. Add me to MSN! | |
| | |
| | #5 (permalink) |
| Super Moderator | You need to put the php code before any browser output otherwise the header() function will fail as you are seeing. Move the <?php.... ?> above the <html> and it should be fine.
__________________ Alex Monaghan - Monaghan Consultants Ltd Web hosting, ADSL, IT & Database consultancy Custom Web hosting on UK or USA servers using Linux (cPanel) or Windows (DotNetPanel) Mobile Phone Ringtones, Logos, Java Games & more |
| | |
| | #6 (permalink) |
| Moderator | Ah, ok, thanks for the help, i will try again when i get home
__________________ Free .org domain - Click for details! Do not pm asking for things. My inbox is full. Add me to MSN! |
| | |
| Tags |
| authentication, http |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| http://www.wallpaperseek.com | tulip4heaven | Website Reviews | 0 | 26-12-2005 15:29 |
| http://www.bintangor.com | Bmg | Ads, Offers & Services | 7 | 06-04-2005 04:07 |
| http://www.knot.in | knot | Buy and Sell Ad Space | 0 | 02-04-2005 14:34 |