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
stann65
Forum Newbie
Posts: 5
Joined: Mon Apr 09, 2007 12:23 pm

403 Forbidden

Post by stann65 »

Hello,

I am new to PHP. I have installed wampserver. What I am trying to do is create a simple shoutbox.
This is the code I currently have;

Code: Select all

<?
//the host, name, and password for your mysql
mysql_connect("localhost","root","password");

//select the database
mysql_select_db("shoutbox");

if($submit)
{
   //use the PHP date function for the time
   $time=date("h:ia d/j/y");
   
   // inserting it into the shoutbox table which we made in the mysql statements before
   $result=MYSQL_QUERY("INSERT INTO shoutbox (ID,name,message,time)".
      "VALUES ('NULL','$name', '$message','$time')");
}
?>
<?
//returning the last 5 messages
$result = mysql_query("select * from shoutbox order by ID desc limit 5");

//the while loop
while($r=mysql_fetch_array($result))
{		
   //getting each variable from the table
   $time=$r["time"]; 
   $ID=$r["ID"];
   $message=$r["message"];
   $name=$r["name"];
?>
   <? echo $time ?><br>
   <? echo $name ?><br>
   <? echo $message ?><br>
<? } ?>
<form action="<? echo $php_self ?>" method="post">
<INPUT TYPE='TEXT' value='name' NAME='name' SIZE=30 maxlength='100'><br>
<INPUT TYPE='TEXT' value='message' NAME='message' SIZE=30 maxlength='100'>
<input type="submit" name="submit" value="submit">
</form>
When I go to http://localhost, and select the php page it allows this, but when I hit the submit button I get a 403 forbidden error, You don't have permission to access /test/< on this server.

As far as I am aware I have everything set up right.

Any help towards fixing this would be much appreciated, thanks, Stann.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I'd guess that you haven't told apache to look at .php files in the directory index list. Try calling your page at /test/index.php and see if that makes it work.

Another thing to try also is looking at the source to see what the form action is. $php_self looks a little suspicious. Where is it set?
stann65
Forum Newbie
Posts: 5
Joined: Mon Apr 09, 2007 12:23 pm

Post by stann65 »

The page the shoutbox is from is called index.php, but when I click submit it tries loading a different page, don't know why.

The $php_self I have no clue about, I got the code from a tutorial but it was a old tutorial with no support to it.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

In your browser, load the initial page. Once it is loaded, view the source (in Firefox, Ctrl-U, in IE, View->Source, in Opera, Ctrl+F3). Look at the part of the HTML that has the <form action=""> and post back what is in the action attribute of the form element.
stann65
Forum Newbie
Posts: 5
Joined: Mon Apr 09, 2007 12:23 pm

Post by stann65 »

<form action="<? echo $php_self ?>" method="post">
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Freaking short tags. Change this:

Code: Select all

<? echo $php_self ?>
to this:

Code: Select all

<?php echo $php_self; ?>
And do the same thing as I mentioned in my last post.

Edit | Now that I look at it, I am seeing short tags everywhere. Do a global find and replace on '<?' turning into '<?php'.
stann65
Forum Newbie
Posts: 5
Joined: Mon Apr 09, 2007 12:23 pm

Post by stann65 »

done, now got <form action="" method="post">
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

That means that the variable $php_self is not being set.

Change:

Code: Select all

<?php echo $php_self; ?>
to

Code: Select all

<?php echo basename(__FILE__); ?>
And see if that does anything different.
stann65
Forum Newbie
Posts: 5
Joined: Mon Apr 09, 2007 12:23 pm

Post by stann65 »

thanks, done that, now displays as <form action="index.php" method="post">.

When I hit submit though the contents of the boxes are not displayed as they should be. All variable names match up to the database table fields created within phpmyadmin. Any ideas?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Based on the suspicious $php_self variable, I would guess that the script is looking for register_globals to be on, which it doesn't appear to be. Which is a good thing. You need to access the form variables using the $_POST superglobal array.
Post Reply