Submit WordPress form programmatically
- by songdogtech
How can I let a user access a WordPress protected page with a URL that will submit the password in the form below?
I want to be able to let a user get to a password protected WordPress page without needing to type the password, so when they go to the page, the password is submitted by a POST URL on page load.
This not intended to be secure in any respect; I'll need to hardcode the password in the URL and the PHP. It's just for simplicity for the user, and once they're in, the cookie will let them in for 10 more days. I will select the particular user with separate PHP function that determines their IP or WordPress login status.
I used Wireshark to find the POST string: post_password=mypassword&Submit=Submit
but using this URL
mydomain.com/wp-pass.php?post_password=mypassword&Submit=Submit
gives me a blank page.
This is the form:
<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:
<?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());
?>
What am I doing wrong? Or is there a better way to let a user into a password protected page automatically?