恼人的错误403,不应该发生

时间:2015-10-23 13:39:33

标签: php apache .htaccess mod-rewrite http-status-code-403

我有一个简单的博客,我可以使用html表单添加一篇文章& php脚本,但我一直收到403错误。我将提供我的所有代码:

添加-post.php中:

<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta name="description" content="" />
        <meta name="keywords" content="" />
        <script type="text/javascript" src="include/jquery-1.9.1.min.js"></script>
    </head>
    <body>
        <form id="form" action="http://website.com/add-post-php.php" method="POST" enctype="multipart/form-data">
            <li class="blockDate"><strong>Post Section</strong></li>
            <li class="blockText">
                <select id="section" name="section">
                    <option value=""></option>
                    <option value="blog">Blog Post</option>
                    <option value="news">News</option>
                    <option value="directory">Friends</option>
                </select>
            </li>
            <li class="blockDate">--</strong></li>
            <li class="blockDate"><strong>Post Categories</strong></li>
            <li class="blockText">
                <select id="category" name="category">
                    <option value=""></option>
                    <option value="posts">Posts</option>
                    <option value="reviews">Reviews</option>
                    <option value="">---</option>
                    <option value="news">News</option>
                    <option value="features">Features</option>
                    <option value="updates">Updates</option>
                    <option value="events">Events</option>
                    <option value="">---</option>
                    <option value="websites">Websites</option>
                    <option value="pro-models">Pro Models</option>
                    <option value="amateur-models">Amateur Models</option>
                    <option value="photographers">Photographers</option>
                    <option value="people">Participants</option>
                    <option value="businesses">Businesses</option>
                </select>
            </li>
            <li class="blockDate">--</strong></li>
            <li class="blockDate"><strong>Post Photo</strong></li>
            <li class="blockText"><input id="photo" name="photo" type="file" /></li>
            <li class="blockDate">--</strong></li>
            <li class="blockDate"><strong>Post Photo Credit</strong></li>
            <li class="blockText"><input type="text" id="credit" name="credit" /></li>
            <li class="blockDate">--</strong></li>
            <li class="blockDate"><strong>Post Title</strong></li>
            <li class="blockText"><input type="text" id="title" name="title" /></li>
            <li class="blockDate">--</strong></li>
            <li class="blockDate"><strong>Post Text</strong></li>
            <li class="blockText"><textarea id="text" name="text"></textarea></li>
            <li class="blockDate">--</strong></li>
            <li class="blockDate"><strong>Post Exclusive</strong></li>
            <li class="blockText">
                <select id="exclusive" name="exclusive">
                    <option value=""></option>
                    <option value="0">No</option>
                    <option value="1">Yes</option>
                </select>
            </li>
            <li class="blockDate">--</strong></li>
            <li class="blockDate">
                <input id="submitform" type="submit" value="Add This" />
            </li>
        </form>
    </body>
</html>

添加--php.php后:

<?php
//Database Connect
$con = mysqli_connect("localhost","user","password","database");
?>
<?php
$id= time();
$month = date("m");
$year = date("Y");
$path = "images/posts/$year/$month/";

$section = stripslashes($_POST["section"]);
$category = stripslashes($_POST["category"]);
$credit = stripslashes($_POST["credit"]);
$title = stripslashes(ucwords($_POST["title"]));
$text = stripslashes($_POST["text"]);
$exclusive = stripslashes($_POST["exclusive"]);

$section = mysqli_real_escape_string($con, $section);
$category = mysqli_real_escape_string($con, $category);
$credit = mysqli_real_escape_string($con, $credit);
$title = mysqli_real_escape_string($con, $title);
$text = mysqli_real_escape_string($con, $text);
$exclusive = mysqli_real_escape_string($con, $exclusive);

$added = date("Y-m-d H:i:s");

$photo = $_FILES["photo"]["name"];
$ext = substr(strrchr($photo, '.'), 1);
?>
<?php
$insert_sql = "INSERT INTO posts (id, section, category, credit, title, article, exclusive, added) VALUES('$id', '$section', '$category', '$credit', '$title', '$text', '$exclusive', '$added')";
$insert_res = mysqli_query($con, $insert_sql);
if(mysqli_affected_rows($con)>0){
move_uploaded_file($_FILES["photo"]["tmp_name"],"$path" . $id . "." . $ext);
}
else{
echo "0";
exit();
};
?>
<?php
$url_title = preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', '', $title);
$url_title = strtolower(str_replace(" ","-",$url_title));
?>
<?php
header("Location: post/$id/$url_title");
exit();
?>

因此,我将详细信息添加到我的add-post.php表单中,然后将其发送到add-post-php.php。问题是我在发送到PHP脚本时遇到错误403(禁止),我不明白为什么。昨天我遇到了很多麻烦,但令人惊讶的是,今天早上我发布的第一件事情它工作正常。 2分钟后,当我添加第二篇文章时,我再次收到错误,整天都是这样。有人可以帮帮我吗?

文件夹:

enter image description here

htaccess的:

Options -MultiViews

DirectoryIndex posts.php

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d    

RewriteRule ^posts/([0-9]+)/?$              posts.php?currentpage=$1 [NC,L,QSA]

RewriteRule ^section/([\w-]+)/?$            section.php?section=$1 [NC,L,QSA]
RewriteRule ^section/([\w-]+)/([0-9]+)/?$   section.php?section=$1&currentpage=$2 [NC,L,QSA]

RewriteRule ^posts/([\w-]+)/?$              posts.php?category=$1 [NC,L,QSA]
RewriteRule ^posts/([\w-]+)/([0-9]+)/?$     posts.php?category=$1&currentpage=$2 [NC,L,QSA]

RewriteRule ^post/([0-9]+)/([\w-]+)/?$      post.php?id=$1&title=$2 [NC,L,QSA]

RewriteRule ^sites/([0-9]+)/?$              sites.php?currentpage=$1 [NC,L,QSA]

RewriteRule ^posts posts.php
RewriteRule ^section section.php
RewriteRule ^sites sites.php

RewriteRule ^about about.php
RewriteRule ^advertise advertise.php
RewriteRule ^subscribe subscribe.php

0 个答案:

没有答案