Jump to content

"HTTP Error 405 - The HTTP verb used to access this page is not allowed"


Wolverine68

Recommended Posts

Trying to run a simple program that, when submitted, stores the username and password as cookies.  When clicking Submit, I get the error  "HTTP Error 405 - The HTTP verb used to access this page is not allowed". If the username and password fields are left blank when submitting it's suppose to give a message to enter a username and password, but, I still get that error message.

 

HTML form:

 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Week 1 Project--Cookies</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />


</head>

<body>
<form action="cookie1.php" method="post">
<h2 align="center">Cookies</h2>

<br />
<div>
<p>Enter your username and password and click "Submit":</p><br />
<p>Username:<input type="text" name="username" size="20"></p>
<p>Password:<input type="text" name="password" size="20"></p>
</div>
<br />
<div><input type="submit" name="submit" value="Submit" /></div>
<br />
<div>
<input type="reset" name="Reset" value="Start Over" />
</div>

</form>



</body>
</html>

 

PHP file:

 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Cookie File</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
<div>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
setcookie('username', $_POST['username'], time() + 2592000);
setcookie('password', $_POST['password'], time() + 2592000);
}
if(($_POST['username'] == "") || ($_POST['password'] == "")) {
print "You must enter both a username and password. Press the Back button on your browser and try again.";
}
else if (isset($_COOKIE['username'])) {
print "Welcome, " .$_COOKIE['username'];
}
?>
</div>
</body>
</html>


Link to comment
Share on other sites

I'm using Brinkster as my host. This is my first time trying to use POST on their server.  I had a free account with them before and that did not run PHP so I upgraded to their Rookie account.

 

Not following you on your second comment. Why won't the PHP script set any cookies?

Link to comment
Share on other sites

You can't have any output sent to the browser before using setcookie(). You should set error_reporting = -1 and display_errors = On in your php.ini file while developing (if you have access to do so).

 

To see if the POST method is cratering the script, paste this into a new file, name it, upload it, run it and click submit.

 

<?php
if( isset($_POST['var']) ) {
echo $_POST['var'];
}
?>
<form method="post" action="">
<input type="hidden" name="var" value="Form field">
<input type="submit" value="Submit">
</form>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.