在 Ubuntu 22.04 上使用 PHP 中的 jQuery Submit 进行 Ajax 调用时收到 403 禁止错误

问题描述 投票:0回答:1

.htaccess 配置,

RewriteEngine On
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?campaign=$1

我在 Ajax 调用中收到 403 错误。

我使用的是 Ubuntu 22.04 LAMP。如果我们需要在 ubuntu 中进行任何更改,那么 kinldy 建议我。

Ajax 调用 - login_process.php

//Proper Working Code
// This was the testing application I developed I know that I do not store encrypted passwords, that is not a good practice. But to practice our main functionality in the code, I used it.

if(isset($_POST['modal_login_email'])){
    include('../_assets/db.php');
    $modal_login_email=mysqli_real_escape_string($conn, $_POST['modal_login_email']);
    $modal_login_password=mysqli_real_escape_string($conn, $_POST['modal_login_password']);
    if(mysqli_num_rows(mysqli_query($conn ,"SELECT `id` FROM `user` WHERE `email`='$email' and `password`='$password'"))>0){
    session_start();
    $row = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM `user` WHERE `email`='$email' and `password`='$password'"));
        $_SESSION['user_id'] = $row['id'];
        $_SESSION['user_token'] = $row['token'];
        header("Location: https://example.com/");die();
    }else{return 'Something Went Wrong With Email Or Password.';}
}

index.php

<form method="post" id="loginForm" name="loginForm">
<input type="email" name="modal_login_email" id="modal_login_email"/>
<input type="password" name="modal_login_password" id=modal_login_password"/>
<button class="btn btn-success" id="modal_login_btn">Login</button>
<div id="login_error_msg" style="color:red;"></div>
</form>

在index.php同一页面,JQuery代码:

jQuery('#loginForm').on('submit',function(e){
        jQuery('#modal_login_btn').val('Please wait...');
        jQuery('#modal_login_btn').attr('disabled',true);
        jQuery.ajax({
            url:'login_process.php',
            type:'post',
            data:jQuery('#loginForm').serialize(),
            dataType: 'html',
            success:function(response){
                jQuery('#login_error_msg').html(response);
                jQuery('#loginForm')['0'].reset();
                jQuery('#modal_login_btn').val('Login');
                jQuery('#modal_login_btn').attr('disabled',false);
            }
        });
        e.preventDefault();
    });

此 JQuery 代码返回 403 禁止错误。 我该如何修复它?感谢您的回复。

更新:在 Apache 错误日志中,我仅获取特定工作目录中所有文件的以下信息:

sudo tail -f /var/log/apache2/error.log

[Time] [access_compat:error] [pid 841806] [client IP] AH01797: client denied by server configuration: /var/www/example.com/dir/login_process.php, referer: https://example.com/dir/
[Time] [access_compat:error] [pid 841744] [client IP] AH01797: client denied by server configuration: /var/www/example.com/dir/login_process.php, referer: https://example.com/dir/
[Time] [access_compat:error] [pid 841806] [client IP] AH01797: client denied by server configuration: /var/www/example.com/dir/login_process.php, referer: https://example.com/dir/

我的 Apache2.conf:

<Directory /var/www/>
    Options FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
php jquery ajax ubuntu ubuntu-22.04
1个回答
0
投票

此错误意味着您的服务器不允许任何请求并拒绝任何传入的 HTTP 请求。要修复此问题,请尝试在 .htaccess 文件或虚拟主机配置文件中添加以下配置(无论您认为合适)(我个人会将其添加到位于 /etc/apache2/sites-available/ 的虚拟主机文件中)。

<Directory /var/www/example.com/>
   Order allow,deny
   Allow from all
   Require all granted
</Directory>
© www.soinside.com 2019 - 2024. All rights reserved.