error - 403 - Access forbidden! - Help Needed

Alles, was PHP betrifft, kann hier besprochen werden.

error - 403 - Access forbidden! - Help Needed

Postby sanei05 » 01. December 2013 13:21

Hi,

I am a newbie to PHP and practising few php codes. I installed xampp 1.8.31 and mysql db 5.5.53 (separate from Xampp) and apache using xampp. I was doing some php coding and below is my code. I am trying to submit a sample text but when I try to do it, I get the following error.

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
Apache/2.4.4 (Win32) OpenSSL/0.9.8y PHP/5.4.19


My php codes is as follows
=========================
Code: Select all
<html>
<head>
<title> Add Joke </title>
</head>
<body>

<?php
if (isset ($_GET['addjoke'])): // If the user wants to add the joke
?>

<form action="<?$_SERVER['PHP_SELF']?>" method="post">
<p> Type your joke here: <br />
<textarea name="joketext" rows="10" cols="40" wrap>
</textarea><br />
<input type="submit" name="submitjoke" value="Submit" />
</p>
</form>
<?php


else: // Default page display

//Connect to the database

$dbcnx =@mysqli_connect("localhost","phpmysql","phpmysql","testmysql");
if (! $dbcnx) {
die ('<p> Unable to connect to database at this time </p>');
}

// If a joke has been submitted , add it to the database
if (isset($_POST['submitjoke'])) {
$sql =  "insert into jokes (joketext,jokedate) values ('$_POST[joketext]','CURDATE()')";
if (@mysqli_query($dbcnx,$sql)){
echo ('<p> Your Joke has been added successfully.</p>');
} else {
echo ('<p> Error in writing the joke to the database. mysqli_error()  </p>');
}
}

echo ('<p> Here are all our jokes in the database. </p>');
//Request for all jokes in the database.

$result=@mysqli_query($dbcnx,"select joketext from jokes");
if(!$result) {
die ('<p> Error in performing query.' .
    mysqli_error($dbcnx) . '</p>');
}

//Display the text of each joke in the paragraph
while ($row=mysqli_fetch_array($result)){
echo ('<p>' . $row['joketext'] . '</p>');
}

//When clicked , this link will load this page with the joke submission form displayed.
echo('<p><a href="' . $_SERVER['PHP_SELF'] .
     '?addjoke=1"> Add a Joke ! </a></p>');

endif;

?>
</body>
</html>



The code is successful without any syntax problem. I googled for this error and was asked to provide "Require All granted" . I provided in httpd.conf file but still the same error. I am getting below error when I refer to error log.

[Sun Dec 01 16:13:58.575798 2013] [core:error] [pid 4968:tid 1764] (20024)The given path is misformatted or contained invalid characters: [client ::1:52661] AH00127: Cannot map POST /website/%3C?$_SERVER['PHP_SELF']?%3E HTTP/1.1 to file, referer: https://localhost/website/addjokes.php?addjoke=1


Can anyone guide me where I am making mistake and what needs to be done.

[edit by Altrea: added code-BBTags to make this post more readable]
sanei05
 
Posts: 4
Joined: 17. November 2013 07:47
Operating System: Windows

Re: error - 403 - Access forbidden! - Help Needed

Postby Altrea » 01. December 2013 13:40

Hi sanei05,

sanei05 wrote:<form action="<?$_SERVER['PHP_SELF']?>" method="post">

Take a minute to look at your form action. I am very sure you will see what is wrong there.

sanei05 wrote:I googled for this error and was asked to provide "Require All granted" . I provided in httpd.conf file but still the same error.

Quickly undo this change.

best wishes,
Altrea
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8286
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: error - 403 - Access forbidden! - Help Needed

Postby sanei05 » 01. December 2013 14:34

Hi Altrea,

Thanks, I modify the form as below and its working fine.

<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
sanei05
 
Posts: 4
Joined: 17. November 2013 07:47
Operating System: Windows


Return to PHP

Who is online

Users browsing this forum: No registered users and 2 guests