Access forbidden! + Error 403

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Access forbidden! + Error 403

Postby curlack » 24. February 2014 22:26

Hello everyone,

So I recently started to implement some PHP within my website for my dissertation. I am by no means familiar with XAMPP, or with PhP that much, but I do what I can to get by.

While trying to impliment some form validation, I keep getting this error message:

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

127.0.0.1
Apache/2.4.7 (Win32) OpenSSL/1.0.1e PHP/5.5.6


This only really seems to be a problem when i'm using this line of code within my form:

action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>

However I have a feeling that it could be a problem beyond just that.

Any help would be appreciated! Thank you

~A final year degree student on the edge
curlack
 
Posts: 6
Joined: 24. February 2014 22:23
XAMPP Version: 5.5.19
Operating System: Windows 7

Re: Access forbidden! + Error 403

Postby Altrea » 24. February 2014 22:44

Hi,

Apache access.log contents?

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: 6596
Joined: 17. August 2009 13:05
XAMPP Version: 5.5.19
Operating System: W7Ux64

Re: Access forbidden! + Error 403

Postby Nobbie » 24. February 2014 22:50

curlack wrote:This only really seems to be a problem when i'm using this line of code within my form:

action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>


.. and therefore you should have checked the source code, which is generated by your PHP script. Obviously, you did not. Do it now. Does the source code and the action clause match your expectations?
Nobbie
 
Posts: 6640
Joined: 09. March 2008 13:04

Re: Access forbidden! + Error 403

Postby curlack » 24. February 2014 22:51

Altrea wrote:Hi,

Apache access.log contents?

best wishes,
Altrea


Hello! :)

127.0.0.1 - - [24/Feb/2014:21:50:33 +0000] "GET /prj/ HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36"
127.0.0.1 - - [24/Feb/2014:21:50:38 +0000] "GET /prj/Contact.html HTTP/1.1" 304 - "http://127.0.0.1/prj/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36"
127.0.0.1 - - [24/Feb/2014:21:50:50 +0000] "GET /prj/Contact.html HTTP/1.1" 304 - "http://127.0.0.1/prj/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36"
127.0.0.1 - - [24/Feb/2014:21:50:50 +0000] "GET /prj/Styles/Style.css HTTP/1.1" 304 - "http://127.0.0.1/prj/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36"
127.0.0.1 - - [24/Feb/2014:21:50:50 +0000] "GET /prj/images/phone.png HTTP/1.1" 304 - "http://127.0.0.1/prj/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36"
127.0.0.1 - - [24/Feb/2014:21:50:50 +0000] "GET /prj/images/header.jpg HTTP/1.1" 304 - "http://127.0.0.1/prj/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36"
127.0.0.1 - - [24/Feb/2014:21:50:50 +0000] "GET /prj/images/map.jpg HTTP/1.1" 304 - "http://127.0.0.1/prj/Contact.html" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36"
127.0.0.1 - - [24/Feb/2014:21:50:50 +0000] "GET /prj/Styles/form.css HTTP/1.1" 304 - "http://127.0.0.1/prj/Contact.html" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36"
127.0.0.1 - - [24/Feb/2014:21:50:50 +0000] "GET /prj/Styles/slidercss.css HTTP/1.1" 304 - "http://127.0.0.1/prj/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36"
127.0.0.1 - - [24/Feb/2014:21:50:50 +0000] "GET /prj/images/email.png HTTP/1.1" 304 - "http://127.0.0.1/prj/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36"
127.0.0.1 - - [24/Feb/2014:21:50:52 +0000] "POST /prj/%3C?php%20echo%20htmlspecialchars($_localhost[ HTTP/1.1" 403 1040 "http://127.0.0.1/prj/Contact.html" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36"


I believe the last line is the one causing the issues? I'm not sure.

Thanks!
curlack
 
Posts: 6
Joined: 24. February 2014 22:23
XAMPP Version: 5.5.19
Operating System: Windows 7

Re: Access forbidden! + Error 403

Postby Altrea » 24. February 2014 23:18

No, which causes the issue can be found here:

127.0.0.1 - - [24/Feb/2014:21:50:38 +0000] "GET /prj/Contact.html HTTP/1.1" 304 - "http://127.0.0.1/prj/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36"


If you want to use PHP, you have to use the file extension .php not .html
=> [FGA] Apache won't parse php code
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: 6596
Joined: 17. August 2009 13:05
XAMPP Version: 5.5.19
Operating System: W7Ux64

Re: Access forbidden! + Error 403

Postby curlack » 24. February 2014 23:21

Altrea wrote:If you want to use PHP, you have to use the file extension .php not .html


That's strange, because you can usually do PHP within a HTML file if it's form validation with that line of code, and i've never had any problems before on other Apache servers.

(code used in form:

<html>
<head>
</head>
<body>

<?php
// define variables and set to empty values
$name = $email = $phone = "";
$nameErr = $emailErr = $phoneErr = "";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{

if (empty($_POST["name"]))
{$nameErr = "Name is required";}
else
{$name = test_input($_POST["name"]);}

if (empty($_POST["email"]))
{$emailErr = "Email is required";}
else
{$email = test_input($_POST["email"]);}

if (empty($_POST["phone"]))
{$phoneErr = "Phone is required";}
else
{$phone = test_input($_POST["phone"]);}
}
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>

<form id="form3" name="form3" method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>
<label for="name">Name:</label><input name="name" id="name" type="text" /> <span class="error">* <?php echo $nameErr;?></span>
<br><br>
<br />
<label for="phone">Phone:</label><input name="phone" id="phone" type="text" /><br />
<label for="email">Email:</label><input name="email" id="email" type="text" /><br />
<p class="message"> Write us a nice message!</span></p>
<textarea id="message" name="message" rows="5" cols="50"></textarea>
<input name="submit" type="submit" value="Submit" />
</form>
</body>
</html>

)
curlack
 
Posts: 6
Joined: 24. February 2014 22:23
XAMPP Version: 5.5.19
Operating System: Windows 7

Re: Access forbidden! + Error 403

Postby Altrea » 24. February 2014 23:25

curlack wrote:That's strange, because you can usually do PHP within a HTML file if it's form validation with that line of code, and i've never had any problems before on other Apache servers.

Just because these other Apache servers are configured to send every html file through the php interpreter (which is very bad practice).
You should not make your script dependend on a single server configuration if not really necessary.
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: 6596
Joined: 17. August 2009 13:05
XAMPP Version: 5.5.19
Operating System: W7Ux64

Re: Access forbidden! + Error 403

Postby curlack » 24. February 2014 23:43

Altrea wrote:Just because these other Apache servers are configured to send every html file through the php interpreter (which is very bad practice).
You should not make your script dependend on a single server configuration if not really necessary.


Well it kind of is necessary? I need form validation that works within the HTML file, and doesn't externally show results in a blank .php page, I also need to pull images from a database in which will be shown within a .html webpage, and if what i've just done is the same then I won't be able to do that either?

If it's possible to change the server configuration then I will do it.
curlack
 
Posts: 6
Joined: 24. February 2014 22:23
XAMPP Version: 5.5.19
Operating System: Windows 7

Re: Access forbidden! + Error 403

Postby Altrea » 24. February 2014 23:49

Sure, it is possible, but why don't you just rename your php containing files?
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: 6596
Joined: 17. August 2009 13:05
XAMPP Version: 5.5.19
Operating System: W7Ux64

Re: Access forbidden! + Error 403

Postby curlack » 24. February 2014 23:58

Altrea wrote:Sure, it is possible, but why don't you just rename your php containing files?


Because like I said, I need the returned PhP values to be within my HTML document because thats where the form, images and styling etc are all centered around. I need the returned "[feild] is required!" message to pop up within my HTML, within this:

Image

If I used an external php file, I wouldn't be able to relay the results into the .html page, would I?

If i'm mistaken, then please let me know. My teachers really do not teach us well.
curlack
 
Posts: 6
Joined: 24. February 2014 22:23
XAMPP Version: 5.5.19
Operating System: Windows 7

Re: Access forbidden! + Error 403

Postby Altrea » 25. February 2014 00:01

Maybe this is not clear:
HTML contents is also valid for php files. The php interpreter is only searching for all PHP-Blocks in it to process it.
So this could also be a valid php file
Code: Select all
<html>
<head>
</head>
<body>

<?php
// define variables and set to empty values
$name = $email = $phone = "";
$nameErr = $emailErr = $phoneErr = "";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{

if (empty($_POST["name"]))
{$nameErr = "Name is required";}
else
{$name = test_input($_POST["name"]);}

if (empty($_POST["email"]))
{$emailErr = "Email is required";}
else
{$email = test_input($_POST["email"]);}

if (empty($_POST["phone"]))
{$phoneErr = "Phone is required";}
else
{$phone = test_input($_POST["phone"]);}
}
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>

<form id="form3" name="form3" method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>
<label for="name">Name:</label><input name="name" id="name" type="text" /> <span class="error">* <?php echo $nameErr;?></span>
<br><br>
<br />
<label for="phone">Phone:</label><input name="phone" id="phone" type="text" /><br />
<label for="email">Email:</label><input name="email" id="email" type="text" /><br />
<p class="message"> Write us a nice message!</span></p>
<textarea id="message" name="message" rows="5" cols="50"></textarea>
<input name="submit" type="submit" value="Submit" />
</form>
</body>
</html>
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: 6596
Joined: 17. August 2009 13:05
XAMPP Version: 5.5.19
Operating System: W7Ux64

Re: Access forbidden! + Error 403

Postby curlack » 25. February 2014 00:08

ahhh thank you i am an idiot you have helped me out a BUNCH thank you so much!!!!
curlack
 
Posts: 6
Joined: 24. February 2014 22:23
XAMPP Version: 5.5.19
Operating System: Windows 7

Re: Access forbidden! + Error 403

Postby Altrea » 25. February 2014 00:11

You are welcome :D
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: 6596
Joined: 17. August 2009 13:05
XAMPP Version: 5.5.19
Operating System: W7Ux64


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 83 guests