403 Forbidden

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Vinnar
Forum Commoner
Posts: 32
Joined: Tue Feb 01, 2011 11:00 am

403 Forbidden

Post 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
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: 403 Forbidden

Post 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?
Vinnar
Forum Commoner
Posts: 32
Joined: Tue Feb 01, 2011 11:00 am

Re: 403 Forbidden

Post 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:
Vinnar
Forum Commoner
Posts: 32
Joined: Tue Feb 01, 2011 11:00 am

Re: 403 Forbidden

Post by Vinnar »

and the same error occurs even if i change die( $error) in connect.php to die(mysqli_error($connect));
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: 403 Forbidden

Post 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.
Last edited by danwguy on Tue Feb 01, 2011 11:48 am, edited 1 time in total.
Vinnar
Forum Commoner
Posts: 32
Joined: Tue Feb 01, 2011 11:00 am

Re: 403 Forbidden

Post by Vinnar »

html

when i go to sendmymail.php it just leaves it as blank
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: 403 Forbidden

Post 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
Vinnar
Forum Commoner
Posts: 32
Joined: Tue Feb 01, 2011 11:00 am

Re: 403 Forbidden

Post by Vinnar »

so u r suggesting it's the web server security issue ?
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: 403 Forbidden

Post 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.
Last edited by danwguy on Tue Feb 01, 2011 12:40 pm, edited 1 time in total.
Vinnar
Forum Commoner
Posts: 32
Joined: Tue Feb 01, 2011 11:00 am

Re: 403 Forbidden

Post 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 ?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: 403 Forbidden

Post 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.
Post Reply