405 error - POST is not allowed for URL?

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
Matt Phelps
Forum Commoner
Posts: 82
Joined: Fri Jun 14, 2002 2:05 pm

405 error - POST is not allowed for URL?

Post by Matt Phelps »

I've been using the POST command throughout my entire scripts with no problems at all but all of a sudden I am having a problem with just one short script and I can't understand it?!

First of all global_variables are ON and so there should be no problem passing variables from this script to anywhere else as far as I know. PHP version on the host server is 4.1.2.

The script is a short form (called loginform.htm) where a user enters a name and password which is then passed on another script that checks the database for the right user/password etc and sets session variables.

When the user submits the form I get a 405 error - The requested method POST is not allowed for URL /project/login.php message.

This whole script works perfectly on my development laptop with Apache (in a console) run on WinME but it refuses to work on my hosts webserver. I have been using multi/part type forms with POST constantly on that webhost (Easyspace, which is a commercial host) and never had this problem before. In fact all the rest of the site uses them everywhere.

Assuming it is something strange with the webhost then there must be a way around it surely? Another way of doing it?

(I have tried changing the loginform html script into a php version by just changing the extension but had the same result.)

Here is the form script. 'loginform.htm'...

Code: Select all

<html>
<head>
<title>AtlasF1 Legends League - COC Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<center><h3>Race Officials Only</h3></center>
<form enctype="multipart/form-data" method="post" action="login.php">
  <p align="center"> <font size="1">Username 
    <input type="text" name="f_user">
    <br>
    Password</font> 
    <input type="password" name="f_pass">
  </p>
  <p align="center">
    <input type="submit" name="Submit" value="Login">
  </p>
  </form>
</body>
</html>
...and 'login.php', the script that recieves the variables...

Code: Select all

<?

// login.php - performs validation 

include("../conf.php");

// authenticate using form variables

$status = authenticate($f_user, $f_pass);

// if  user/pass combination is correct
if ($status == 1)
&#123;
	// initiate a session
	session_start();
	
	// register some session variables
	session_register("SESSION");

	// including the username
	session_register("SESSION_UNAME");
	$SESSION_UNAME = $f_user;
	
	// redirect to protected page
	header("Location: ../coc/desktop.php");
	exit();
&#125;
else
// user/pass check failed
&#123;
	// redirect to error page
	header("Location: ../error.php?e=$status");
	exit();
&#125;

// authenticate username/password against a database
// returns: 0 if username and password is incorrect
//          1 if username and password are correct

function authenticate($user, $pass)
&#123;
	$db_name = 'project';
	
	// check login and password
	// connect and execute query
	
	$query = "SELECT uid from user WHERE uname = '$user' AND pass = '$pass' AND admin = '1' ";
	mysql_select_db($db_name);
	$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
	$check = mysql_num_rows($result);
	
	// if row exists -> user/pass combination is correct
	
	if ($check == '1')
	&#123;
		return 1;
	&#125;
	// user/pass combination is wrong
	else
	&#123;
		return 0;
	&#125;
&#125;

?>
User avatar
Kadmin
Forum Newbie
Posts: 7
Joined: Sat Jul 06, 2002 2:39 am
Location: Missouri, USA

Post by Kadmin »

Not much help here, but the ONLY time I've seen this,
(and I have) was a filename or permissions error on
the server. I'm sorry that I am not sure of your answer,
and that I can't remember exactly which it was. After
it hit me in the face, I got it easily fixed. :)
f1nutter
Forum Contributor
Posts: 125
Joined: Wed Jun 05, 2002 12:08 pm
Location: London

Post by f1nutter »

If its any help, Easyspace use Zeus, not Apache as I have just found out. You might have fixed your problem by now anyway.
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Do you get any errors? It could be MySQL so try adding echo mysql_error() just after you executed the query.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

what happens if you call the page without any parameters (not GET-, no POST-data, just the link) ?
a 405 usually means that there is no handler for the mime-type of the requested document that can possibly fetch the request-data.
Post Reply