PDA

View Full Version : Login Feature (To see pages)



Unseen Ghost
12-07-2005, 10:14 PM
Hey guys, I was wondering is there a DynamicDrive code to login to see a page or pages?

Pretty sure this is a PHP coding question, but it may be ASP, so sorry if I posted in wrong area.

Just in case you need my site, here it is. Website (http://polh.alienationskins.com/?act=idx)

Thanks a lot guys.

Twey
12-08-2005, 05:42 PM
You can do it in either language. I don't know ASP, so in PHP:

<?php
$password = "put your password here";

$login_form = <<<END
<!-- Put your login form here, in plain HTML. -->
<html>
<head>
<title>Authorization Required</title>
</head>
<body>
<p>
This page is for members only. If you are a member, please enter your password below. If not, please leave this page.
</p>
<fieldset>
<form action="$PHP_SELF" method="post">
<legend>Password</legend>
<input type="password" name="password"/>
<input type="submit" value="OK"/>
</form>
</fieldset>
</body>
</html>

END;
$login_failed = <<<END
<!-- Put your "authorization failed" page here, in plain HTML. -->
<html>
<head>
<title>Authorization Failed</title>
</head>
<body>
<p>
Your login failed! Please try again by entering your password in the field below.
</p>
<fieldset>
<form action="$PHP_SELF" method="post">
<legend>Password</legend>
<input type="password" name="password"/>
<input type="submit" value="OK"/>
</form>
</fieldset>
</body>
</html>

END;
session_start();
if(!isset($_SESSION['logged_in']) && !isset($_POST['password']))
die($login_form);
if(isset($_POST['password']))
if($_POST['password'] == $password)
$_SESSION['logged_in'] = 1;
else die($login_failed);
?>Save this to a seperate file (such as security.php), then, at the top of your file(s) (before anything else), put:
include("security.php");Untested.