PhpSnip.com

User Stats

Super Simple Password Protect

I've found the need to password protect a few webpages and didn't feel like setting up a "real" authentication scheme. This is pretty cheesy, but good for someone who has a webpage and wants to make the information only available to a select few.

Info

 Download  View Source (print view)
 Rating : 4.7  Views : 255

Source Code ( 48 lines )

<HTML>
<HEAD>
<TITLE>Some Title</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">
<center><img src="somecoolimage.jpg"></center>

<?php
$login = foo;
$password = bar;

if (isset($form[login]) && isset($form[password])){
	if (($login == $form[login]) && ($password == $form[password])){

print("Put all the HTML here");

}else{
	print("<h3>Invalid Login</h3><br><br><FORM method=post>");
	print("<table>
	<tr>
	<td><b>Login</b></td>
		<td><b>Password</b></td>
	</tr>
	<tr>
		<td><input type=text name='form[login]'></td>
		<td><input type=password name='form[password]'></td>	
	</tr>
</table>
<br><br><input type=submit value=Login></form>");
}
}else{
	print("<h3>&nbsp</h3><br><br>

<FORM method=post><table>
	<tr>
	<td><b>Login</b></td>
		<td><b>Password</b></td>
	</tr>
	<tr>
		<td><input type=text name='form[login]'></td>
		<td><input type=password name='form[password]'></td>	
	</tr>
</table>
<br><br><input type=submit value=Login></form>");
}
?>
</BODY>
</HTML>

Search

Subscribe

  Rss Feeds

Sponsors

Advertise