php - Strange Forbidden 403 Error - Solution Needed -
i have blog add-post.php
page contains simple form action:
<form id="form" action="add-post-php.php" method="post" enctype="multipart/form-data">
i have file, add-post-php.php
in same folder add-post.php
. enter details of blog form , press submit , get:
forbidden
you don't have permission access /add-post-php.php on server.
additionally, 404 not found error encountered while trying use errordocument handle request.
- i've tested on localhost , works correctly
- the permission of file set @ 0644, i've tried @ 0755, no improvement.
- there nothing wrong .htaccess file , there no other .htaccess files in directory.
- i've tried using full url path in form
action
my add-post-php.php
script in full is:
<?php include("php/settings.php"); // contains db connections ?> <?php $id= time(); $month = date("m"); $year = date("y"); $path = "images/posts/$year/$month/"; $section = $_post["section"]; $category = $_post["category"]; $credit = $_post["credit"]; $title = ucwords($_post["title"]); $text = $_post["text"]; $exclusive = $_post["exclusive"]; $added = date("y-m-d h:i:s"); $photo = $_files["photo"]["name"]; $ext = substr(strrchr($photo, '.'), 1); ?> <?php $insert_sql = "insert 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 header("location: post.php?id=$id"); exit(); ?>
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¤tpage=$2 [nc,l,qsa] rewriterule ^posts/([\w-]+)/?$ posts.php?category=$1 [nc,l,qsa] rewriterule ^posts/([\w-]+)/([0-9]+)/?$ posts.php?category=$1¤tpage=$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
and folder structure:
i've checked php error log
, there's nothing suspicious there. have idea why i'm getting forbidden error when file exists , it's permissions correct?
i found problem include
statement within add-post-php.php
file:
<?php include("php/settings.php"); // contains db connections ?>
i took out , changed to:
<?php //database connect $con = mysqli_connect("localhost","username","password","database"); ?>
the script worked edited line of code.
Comments
Post a Comment