•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 426,136 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,783 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 970 | Replies: 5
![]() |
The following cod,when I press the SUBMIT button , I get "Forbidden, You don't have permission to access /< on this server."
The funny thing is that 2 month ago,the same code , on the same machine worked.
Now I tried on a different pc,I install/unistall dozens of wamp versions , I don't have a clue what could be wrong
As the code says,I'm running it on the same computer ( localhost )
<html>
<head>
<title> The Internet Joke Database </title>
</head>
<body>
<?php
if (isset($_GET['addjoke'])): // If the user wants to add a joke
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<p>Type your joke here:<br />
<textarea name="joketext" rows="10" cols="40" wrap>
</textarea><br />
<input type="submit" name="submitjoke" value="SUBMIT" />
</p>
</form>
<?php
else: // Default page display
// Connect to the database server
$dbcnx = @mysql_connect('localhost', 'root', 'mypasswd');
if (!$dbcnx) {
die( '<p>Unable to connect to the ' .
'database server at this time.</p>' );
}
// Select the jokes database
if (! @mysql_select_db('jokes') ) {
die( '<p>Unable to locate the joke ' .
'database at this time.</p>' );
}
// If a joke has been submitted,
// add it to the database.
if (isset($_POST['submitjoke'])) {
$joketext = $_POST['joketext'];
$sql = "INSERT INTO Jokes SET
JokeText='$joketext',
JokeDate=CURDATE()";
if (@mysql_query($sql)) {
echo('<p>Your joke has been added.</p>');
} else {
echo('<p>Error adding submitted joke: ' .
mysql_error() . '</p>');
}
}
echo('<p> Here are all the jokes in our database: </p>');
// Request the text of all the jokes
$result = @mysql_query('SELECT JokeText FROM Jokes');
if (!$result) {
die('<p>Error performing query: ' .
mysql_error() . '</p>');
}
// Display the text of each joke in a paragraph
while ( $row = mysql_fetch_array($result) ) {
echo('<p>' . $row['JokeText'] . '</p>');
}
// When clicked, this link will load this page
// with the joke submission form displayed.
echo('<p><a href="' . $_SERVER['PHP_SELF'] .
'?addjoke=1">Add a Joke!</a></p>');
endif;
?>
</body>
</html>Now I tried on a different pc,I install/unistall dozens of wamp versions , I don't have a clue what could be wrong
As the code says,I'm running it on the same computer ( localhost )
Last edited by Eko : May 8th, 2007 at 6:53 pm.
"Get rich or die tryin"(50-cent)
•
•
Join Date: May 2007
Location: Bucharest, RO
Posts: 67
Reputation:
Rep Power: 2
Solved Threads: 4
That's because you try to use short_open_tag (<? instead of <?php ) as your php openning tag in [php]<form action="<?=$_SERVER['PHP_SELF']?>" method="post">[/php] while you probably have it set in your php.ini to off:
short_open_tag = Off
That's why, when you run the script, your form looks like this:
[php]<form action="<?=$_SERVER['PHP_SELF']?>" method="post">[/php] instead of [php]<form action="/path_to_your_file.php" method="post">[/php] hence the error.
On your previous server (configuration) (2 months ago), you probably had short_open_tag = On , and that's why the same script worked.
Php reccomends in php.ini to avoid using short_open_tag in your scripts, exactly beacuse of this. On some servers this option is not enabled and you get in a lot of trouble, the way you did.
So, to solve your problem, try to use:
[php]<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">[/php]
short_open_tag = Off
That's why, when you run the script, your form looks like this:
[php]<form action="<?=$_SERVER['PHP_SELF']?>" method="post">[/php] instead of [php]<form action="/path_to_your_file.php" method="post">[/php] hence the error.
On your previous server (configuration) (2 months ago), you probably had short_open_tag = On , and that's why the same script worked.
Php reccomends in php.ini to avoid using short_open_tag in your scripts, exactly beacuse of this. On some servers this option is not enabled and you get in a lot of trouble, the way you did.
So, to solve your problem, try to use:
[php]<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">[/php]
Last edited by johny_d : May 8th, 2007 at 7:36 pm.
•
•
Join Date: May 2007
Location: Bucharest, RO
Posts: 67
Reputation:
Rep Power: 2
Solved Threads: 4
•
•
Join Date: Apr 2005
Location: Old Hampshire, Old England (LOL)
Posts: 11,937
Reputation:
Rep Power: 30
Solved Threads: 268
I think the reason it worked then didnt is did you upgrade?
a new version (i myself use XAMPP) came out recenly and the same thing happened to me. Seems they turned off the short tags as its the new default behaviour?
a new version (i myself use XAMPP) came out recenly and the same thing happened to me. Seems they turned off the short tags as its the new default behaviour?
TRY MY SUGGESTIONS AT YOUR OWN RISK!
james.bennet1@ntlworld.com
james.bennet1@ntlworld.com
I've used wamp 1.5.0 , 1.5.0.a , 1.7.1 , 1.4.2
All of them have the short_open_tag = Off by default , and I guess that all future versions will have this as well
It can be really frustrating.
They should ask you when u install it , if you want short tag on/off
All of them have the short_open_tag = Off by default , and I guess that all future versions will have this as well
It can be really frustrating.
They should ask you when u install it , if you want short tag on/off
Last edited by Eko : May 9th, 2007 at 7:55 pm.
"Get rich or die tryin"(50-cent)
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- strange problem (C)
- Strange Boot Problems (Troubleshooting Dead Machines)
- ERROR with my email, getting sent strange emails :( (Geeks' Lounge)
- getting strange values in display??? (C++)
- Strange 'glitching' - possibly CPU issue (Motherboards, CPUs and RAM)
- strange problems (Windows 9x / Me)
- Suspected virus issue (Windows NT / 2000 / XP / 2003)
- HELP!!! very strange problem! (Troubleshooting Dead Machines)
- win2000pro SP3 hangs in strange way (Windows NT / 2000 / XP / 2003)
Other Threads in the PHP Forum
- Previous Thread: Basic PHP
- Next Thread: ugh.. silly script



Linear Mode