Page 1 of 1

403 Forbidden

Posted: Mon Apr 09, 2007 12:35 pm
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.

Posted: Mon Apr 09, 2007 12:45 pm
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?

Posted: Mon Apr 09, 2007 12:55 pm
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.

Posted: Mon Apr 09, 2007 1:34 pm
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.

Posted: Mon Apr 09, 2007 2:25 pm
by stann65
<form action="<? echo $php_self ?>" method="post">

Posted: Mon Apr 09, 2007 2:28 pm
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'.

Posted: Mon Apr 09, 2007 2:39 pm
by stann65
done, now got <form action="" method="post">

Posted: Mon Apr 09, 2007 5:17 pm
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.

Posted: Mon Apr 09, 2007 5:28 pm
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?

Posted: Mon Apr 09, 2007 5:36 pm
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.