Kevin's article, "Managing Users with PHP Sessions and MySQL" is the clearest I've seen. I thought I had adapted it to my needs, which are basically just to log users in who already have a username and password, then maintain their sessions. I keep getting the following error when I try the test page. I've spent a couple of hours trying to find the error. Please spot it if you can. (I've used "my..." where I'm hiding my actual directories.)
Error message:
Parse error: parse error in /home/myusername/mylib/accesscontrol.php on line 63
Here's the test page :
<?php // include("accesscontrol.php"); ?>
<?php require('/home/myusername/mylib/accesscontrol.php');?>
<html>
<head>
<title> Members-Only Page </title>
</head>
<body>
<p>Welcome, <?=$username?>! You have entered a members-only area of the site. Don't you feel special?</p>
</body>
</html>
Here's my slightly modified version of Kevin's script :
<?php // accesscontrol.php
include("common.php");
include("db.php");
session_start();
if(!isset($txtName)) {
?>
<html>
<head>
<title> Please Log In for Access </title>
</head>
<body>
<h2> Login Required </h2>
<p>You must log in to access this area of the site.<p>
<form method="post" action="<?=$PHP_SELF?>">
User ID: <input type="text" name="txtName" size="12"><br>
Password: <input type="password" name="password" SIZE="12"><br>
<input type="submit" value="Log in">
</form></p>
</body>
</html>
<?php
exit;
session_register("txtName");
session_register("password");
dbConnect("my_database");
$sql = "SELECT * FROM sspass WHERE ss = '$txtName' AND pwd = '$password'";
$result = mysql_query($sql);
if (!$result) {
error("A database error occurred while checking your login details.");
}
if (mysql_num_rows($result) == 0) {
session_unregister("txtName");
session_unregister("password");
?>
<html>
<head>
<title> Access Denied </title>
</head>
<body>
<h2> Access Denied </h2>
<p>Your user ID or password is not found. To try logging in again, click
<a href="<?php echo $PHP_SELF; ?>">here</a>.</p>
</body>
</html>
<?php
exit;
}
?>





Bookmarks