[SOLVED] Gremlins in simple PHP auth script
Posted: Fri Jan 30, 2004 1:04 am
Decided to start messing around with PHP/MySQL...and it seems pretty sweet. Unfortunately, I can't even seem to get my frist script right and I've been working on it all day (chasing the aforementioned gremlins for the most part). This script is NOT meant to be a massively secure piece of work; rather it's simply to keep a couple of my g/f's friends out of the main content of the locally hosted (as in apache on localhost) site I'm doing for her...so it doesn't need to be anything too heavy. Also, this was done as an attempt to modify the script I've been working with as part of a tutorial I found.
Anyway, here we go, I suppose.
The specific error I receive when I try to load the file is "Parse error: parse error, unexpected $end in <directory>\ndex.php on line 52". I've checked and re-checked quotations (both double and single), braces, and parentheses. I'm lost...any help is VERY greatly appreciated.
Again, thanks in advance for any suggestions.
Anyway, here we go, I suppose.
The specific error I receive when I try to load the file is "Parse error: parse error, unexpected $end in <directory>\ndex.php on line 52". I've checked and re-checked quotations (both double and single), braces, and parentheses. I'm lost...any help is VERY greatly appreciated.
Code: Select all
<?php
if ($submit) {
$db = mysql_connect("localhost", "root", "");
mysql_select_db("DBname", $db);
$sql = "SELECT auth_level FROM user WHERE username = '$username' AND password = '$password' ";
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$auth_level = $rowї"auth_level"];
}
// Retrieve the authorization level from the table
// where the username and password are equal to
// the values submitted (simple Auth...just with
// permissions).
if (!mysql_num_rows($result)) {
echo "Whoa! Your credentials ain't no good here! Why don't ya bug me or my girlfriend for a proper login? Then again, you could just try again...with a correct password...";
// just bitches at the user for not being logged in/properly authed
} else {
setcookie('username', $_POSTї'username'], (time()+2592000), '/', '', 0);
setcookie('auth_level', $_POSTї'auth_level'], (time()+2592000), '/', '', 0);
}
//if credentials are good, set the cookie for both username and auth level
if ($auth_level == "3") {
header('Location: login.php');
} elseif ($auth_level == "2") {
header('Location: login.php');
} elseif ($auth_level == "1") {
header('Location: login.php');
} elseif ($auth_level == "0") {
header('Location: login.php');
}
else {
?>
<form method="POST" action="<?php echo $GLOBALS ї'PHP_SELF'];?>">
Name: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="submit" name="submit" value="Login">
</form>
<?php
}
?>