Hello, I am new PHP beginner. Currently I am try using XAMPP to develop an online auction based on the chapter 7 of the e-book, "Practical PHP & MySQL" , the link:http://utopia.duth.gr/~stavtran/vivlia/PHP_and_MySQL.pdf
However, I faced problem with the login page. When I try login with the correct username & password, the page direct show:
Access forbidden!
You don't have permission to access the requested object. It is either read-protected or not readable by the server.
If you think this is a server error, please contact the webmaster.
Error 403
localhost
24/4/2012 1:32:44 AM
Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1
My coding for the login.php (based on the e-book, page 240) is as following:
<?php
session_start();
require("config.php");
require("functions.php");
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);
if($_POST['submit']) {
$sql = "SELECT * FROM users WHERE username = '" . $_POST['username'] . "' AND password = '" . $_POST['password'] . "';";
$result = mysql_query($sql);
$numrows = mysql_num_rows($result);
if($numrows == 1) {
$row = mysql_fetch_assoc($result);
if($row['active'] == 1) {
session_register("USERNAME");
session_register("USERID");
$_SESSION['USERNAME'] = $row['username'];
$_SESSION['USERID'] = $row['id'];
switch($_GET['ref']) {
case "addbid":
header("Location: " . $config_basedir
. "/itemdetails.php?id=" . $_GET['id'] . "#bidbox");
break;
case "newitem":
header("Location: " . $config_basedir . "/newitem.php");
break;
case "images":
header("Location: " . $config_basedir
. "/addimages.php?id=" . $_GET['id']);
break;
default:
header("Location: " . $config_basedir);
break;
}
}
else {
require("header.php");
echo "This account is not verified yet. You were
emailed a link to verify the account. Please click on the
link in the email to continue.";
}
}
else {
header("Location: " . $config_basedir . "/login.php?error=1");
}
}
else {
require("header.php");
echo "<h2>Login</h2>";
if($_GET['error']) {
echo "Incorrect login, please try again!";
}
?>
<form action="<?php echo
pf_script_with_get($SCRIPT_NAME); ?>" method="post">
<table>
<tr>
<td>Username</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Login!"></td>
</tr>
</table>
</form>
Don't have an account? Go and <a href="register.php">Register</a>!
<?php
}
require("footer.php");
?>
I don't know whether it was coding error or server setting problems.
Anyone please kindly teach me to solve the problem. Thank You. 🙂