Wolverine68 Posted May 3, 2011 Share Posted May 3, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/235465-http-error-405-the-http-verb-used-to-access-this-page-is-not-allowed/ Share on other sites More sharing options...
Pikachu2000 Posted May 3, 2011 Share Posted May 3, 2011 Have you successfully used forms with the POST method on this server in the past? As a sidenote, the second script will not successfully set any cookies. You can't have anything at all output to the browser before using setcookie. Quote Link to comment https://forums.phpfreaks.com/topic/235465-http-error-405-the-http-verb-used-to-access-this-page-is-not-allowed/#findComment-1210159 Share on other sites More sharing options...
Wolverine68 Posted May 4, 2011 Author Share Posted May 4, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/235465-http-error-405-the-http-verb-used-to-access-this-page-is-not-allowed/#findComment-1210171 Share on other sites More sharing options...
Pikachu2000 Posted May 4, 2011 Share Posted May 4, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/235465-http-error-405-the-http-verb-used-to-access-this-page-is-not-allowed/#findComment-1210194 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.