Page 1 of 1

403 Forbidden

Posted: Tue Feb 01, 2011 11:06 am
by Vinnar
Hi guys, this is my first time posting in forum !!!!! :D

so i keep getting this error, 403 Forbidden:

Forbidden

You don't have permission to access (/directory/) on this server.

for everytime I try to run my php scripts which have access to database. But when I run php scripts without accessing database, there would be no problems.

Is this a problem with MySQL? I have checked a lot of times in my connection.php page that my mysqli_connect( ) has everything right, including user name and password shown on the web hosting server, as well as mysqli_select_db ( ) with a correct databasename.

Still no success and this error keeps arising.

Any help is appreciated ! :P

Re: 403 Forbidden

Posted: Tue Feb 01, 2011 11:26 am
by danwguy
Best I can say is post up some of your connect code and let us see if we can find where the error is. Are you using "or die("Error: " .mysql_error());" in your connect script?

Re: 403 Forbidden

Posted: Tue Feb 01, 2011 11:39 am
by Vinnar
This is the connection.php

Code: Select all

<?php

function db(){$error = "Couldn't connect";
global $connect;
$connect = mysqli_connect("localhost", "root", "********") or die($error);
$db_select = mysqli_select_db($connect, "database");	
}


?>
and it is used in the following script:

Code: Select all

<?php

include ('connect.php');

if($_POST[op] != "send") {

	include('sendmymailform.html');

} else if ($_POST[op] == 'send'){
	
	if (($_POST[subject] == "" || ($_POST[message] == ""))) {
	
		header("Location: sendmymailform.html");
		exit();
	
	}
	
	db();
	$sql = "SELECT email from users where email = 'asdfasdfasdf@hotmail.com'";
	$result = mysqli_query($connect, $sql) or die(mysqli_error($connect));
	
	$headers = "From: asdfasd@dasdfasdfasd.com\n";
	
	while ($row = mysqli_fetch_array($result)){
	
		set_time_limit(0);
		$email = $row['email'];
		mail("$email", stripslashes($_POST[subject]), stripslashes($_POST[message]), $headers);
		print "newsletter sent to: $email<br>";
	
	}

}

?>

:

and this is the html script:

Code: Select all

	<html>
	<head>
	<title>Send a newsletter</title>
	</head>
		<body>
			<h1>Send a Newsletter</h1>
			<form method="post" action = "sendmymail.php">
			<p><b>Subject:</b></p>
			<input type="text" name="subject" size = "30"></p>
			<p><b>Message:</b></p>
			<textarea name = "message" cols = "50"	row = "10"	wrap = "virtual"></textarea>
			<input type = "hidden" name="op" value="send">
			<p><input type = "submit" name = "submit" value = "Send it"></p>
			</form>
		</body>
	</html>
but when i upload all these files to web server, and type in the URL accordingly then the 403 Forbidden error pops up .... :banghead:

Re: 403 Forbidden

Posted: Tue Feb 01, 2011 11:45 am
by Vinnar
and the same error occurs even if i change die( $error) in connect.php to die(mysqli_error($connect));

Re: 403 Forbidden

Posted: Tue Feb 01, 2011 11:46 am
by danwguy
You are getting the 403 forbidden error when you go to just the html page? Or is it just after you fill out the form and hit send, then you get the 403? and for testing you should allow it to show you what the error is instead of defining what to say let it tell you what the error is and I would do another or die after you attmept to select the db.

Re: 403 Forbidden

Posted: Tue Feb 01, 2011 11:48 am
by Vinnar
html

when i go to sendmymail.php it just leaves it as blank

Re: 403 Forbidden

Posted: Tue Feb 01, 2011 11:50 am
by danwguy
try this page out and see do what it says then let me know if you still have the problem...
http://www.checkupdown.com/status/E403.html

Re: 403 Forbidden

Posted: Tue Feb 01, 2011 12:30 pm
by Vinnar
so u r suggesting it's the web server security issue ?

Re: 403 Forbidden

Posted: Tue Feb 01, 2011 12:37 pm
by danwguy
Yep, try putting the html and php files where they need to go on the web server, and making links to them from within the other html pages and go about it that way. Like the article says, most web hosting companies turn of directory browsing so the only way to get to that file without the 403 error is to link to it from within your home page. As far as your code looks, there isn't any obvious errors that would crash the page out like that, there are somethings I would do differently, but over all it looks like it should work fine.

Re: 403 Forbidden

Posted: Tue Feb 01, 2011 12:39 pm
by Vinnar
lol i just found out the solution

and it's kinda stupid ....

it's all cuz of the extension. so if i use sendmymailform.php instead of html, it works fine

anyway thx a LOT for ur help man really appreciate it :D

btw i am wondering y the html extension cause such a problem ?

Re: 403 Forbidden

Posted: Tue Feb 01, 2011 12:50 pm
by John Cartwright
Vinnar wrote:btw i am wondering y the html extension cause such a problem ?
HTML extension by default, according to Apache (or whatever server your using) will not be mapped to the PHP processor. It will be treated as plain HTML.