How can I allow a user to access a secure WordPress page with a URL that will send a password in the form below?
I want the user to be able to go to the password protected WordPress page without having to enter a password, so when they go to the page, the password is sent by the POST URL when the page loads.
This is not intended to be safe in any way; I need to hardcode the password in the URL and PHP. It is just for simplicity for the user.
Edit 4/19/10: According to the answers below, you can set cookies directly so that users cannot enter a password. Allowing the search for bots is best done by detecting the user agent and redirecting, since the bots will not process cookies.
This is the form (which is the main WordPress code):
<form action="http://mydomain.com/wp-pass.php" method="post">
Password: <input name="post_password" type="password" size="20" />
<input type="submit" name="Submit" value="Submit" /></form>
This is wp-pass.php (which is the main WordPress code):
<?php
require( dirname(__FILE__) . '/wp-load.php');
if ( get_magic_quotes_gpc() )
$_POST['post_password'] = stripslashes($_POST['post_password']);
setcookie('wp-postpass_' . COOKIEHASH, $_POST['post_password'], time() + 864000, COOKIEPATH);
wp_safe_redirect(wp_get_referer());
?>
source
share