【问题标题】:How do I resolve forbidden access problem in XAMPP如何解决 XAMPP 中的禁止访问问题
【发布时间】:2018-10-14 15:02:23
【问题描述】:

我一直在尝试在 xampp 上实现以下购物车网站。该页面的链接是:http://www.w3programmers.com/build-a-shopping-cart-with-php-part-1/

但是,当我尝试运行我的登录页面时,我收到以下错误:-

这是我尝试登录时打开的标签:

这是登录代码:-

<?php
session_start();

require("config.php");
if(isset($_SESSION['SESS_LOGGEDIN']) == TRUE) {
header("Location:".$config_basedir);    
}

if($_POST['submit'])
{
$loginsql = "SELECT * FROM logins WHERE username = '" . $_POST['userBox']. "' AND password = '" . $_POST['passBox'] . "'";
$loginres = mysql_query($loginsql);
$numrows = mysql_num_rows($loginres);
if($numrows == 1)
{
$loginrow = mysql_fetch_assoc($loginres);
session_register("SESS_LOGGEDIN");
session_register("SESS_USERNAME");
session_register("SESS_USERID");
$_SESSION['SESS_LOGGEDIN'] = 1;
$_SESSION['SESS_USERNAME'] = $loginrow['username'];
$_SESSION['SESS_USERID'] = $loginrow['id'];
$ordersql = "SELECT id FROM rides WHERE customer_id = " . $_SESSION['SESS_USERID'] . " AND status < 2"; 
$orderres = mysql_query($ordersql); 
$orderrow = mysql_fetch_assoc($orderres); 
session_register("SESS_ORDERNUM"); $_SESSION['SESS_ORDERNUM'] = $orderrow['id'];
 header("Location:".$config_basedir);
}
else {
header("Location:http://" .$_SERVER['HTTP_HOST']. $_SERVER['SCRIPT_NAME'] . "?error=1");
}
}
else {
require("header.php");
?>
<h1>Customer Login</h1>

Please enter your username and password to log into the websites. If you do not have an account, you can get one for free by <a href="register.php">registering</a>.

<?php
if(isset($_GET['error'])) {
echo "<strong>Incorrect username/password</strong>";
}
?>
<form action="<?php $_SERVER['SCRIPT_NAME']; ?><br />" method="POST">
<table>
<tbody>
<tr>
<td>Username</td>
<td><input type="textbox" name="userBox" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="passBox" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Log in" /></td>
</tr>
</tbody>
</table>
</form>

<?php
}
require("footer.php");
?>

这是标题代码:-

<?php
    session_start();
    if(isset($_SESSION['SESS_CHANGEID'])==TRUE){
        session_unset();
        session_regenerate_id();
    }
    require("config.php");

    $db = mysql_connect($dbhost, $dbuser, $dbpassword);

    mysql_select_db($dbdatabase, $db);
?>


        <head>
            <title><?php echo $config_sitename; ?></title>
            <meta charset="utf-8"/>
            <link rel="stylesheet" type="text/css" href="../stylesheet.css">
        </head>
        <body>
            <div id="header">
                <h1><?php echo $config_sitename; ?></h1>
            </div>
            <div id="menu">
                <a href="<?php echo $congif_basedir; ?>">Home</a>
                <a href="<?php echo $congif_basedir; ?>">View Rides</a>
            </div>  
            <div id="container">
                <div id="bar">
                    <?php
                        require("bar.php");
                        echo "<hr>";

                        if(isset($_SESSION['SESS_LOGGEDIN'])==True){
                            echo "Logged in as <strong>".$_SESSION['SESS_USERNAME']."</strong>[<a href='".$congif_basedir."logout.php'>logout</a>]";
                        }else{
                            echo "<a href='".$config_basedir."login.php'>Login</a>";    
                        }
                    ?>
                </div>  

            <div id="main">

我怀疑这与 header 函数有关,但我不太确定。

【问题讨论】:

  • 看起来像 Chrome。请问可以换个浏览器试试吗
  • 另外,您真的非常非常好应该寻找更好的更新教程。特别是一个不使用旧的现在已删除的 mysql_ 数据库访问 API
  • PS:来自 Apache 的这条消息与您的代码无关。 Apache 没有让你进入,所以 Apache 甚至还没有找到代码
  • @RiggsFolly 我在 Firefox 中尝试过,但结果相同,我什至尝试在 httpd-xampp 中更改 xampp 权限。

标签: php mysql xampp


【解决方案1】:

我可以请你把来自 config.php 的代码放在这里吗?或者至少告诉 $config_basedir 的值是多少?

更新:$config_basedir 应该是这种格式的 URL:http://localhost/ . 'some folders' . 'file name with extension',例如,像这样:http://localhost/sites/shop/index.php。

如果文件或文件的文件夹位于同一目录或子目录中,则您的 URL 可以是:文件'file_name 或folder/file_name。例如只是index.php 或folder/folder/index.php。

根据您的服务器设置,.php | .html 之类的扩展名可能不是强制性的。也就是你可以这样指明URL:folder/index或index; 'index' - 在这种情况下是一个文件名。

【讨论】:

    猜你喜欢
    • 2015-11-11
    • 2020-07-10
    • 2018-10-07
    • 2013-07-22
    • 1970-01-01
    • 2019-01-12
    • 2013-01-19
    • 2014-10-22
    • 2017-02-20
    相关资源
    最近更新 更多