Mr.Canuck Posted August 1, 2013 Share Posted August 1, 2013 Hey everyone. Is there a simple PHP script that would let me set up a page where a user just enters a password and clicks "submit". If the password is correct, then they get re-directed to a specific URL. Any help would be appreciated. Quote Link to comment Share on other sites More sharing options...
requinix Posted August 1, 2013 Share Posted August 1, 2013 60 seconds. Really simple stuff here. <?php if (isset($_POST["password"]) && $_POST["password"] == "correct password") { header("Location: http://www.example.com"); exit; } ?> <html> <body> <form action="" method="post"> <p><input type="password" name="password" /> <input type="submit" /></p> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
Mr.Canuck Posted August 1, 2013 Author Share Posted August 1, 2013 Thanks. Here is the PHP password code that I already have. Currently it send me to the protected page content when the password is entered. Can I have it send me to a specific URL instead, like http://whatever.com ? <?php function my_password_form() { global $post; $label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID ); $o = '<form class="protected-post-form" action="' . get_option( 'siteurl' ) . '/wp-login.php?action=postpass" method="post"> ' . __( "To enter our client area, please enter the password which was provided to you:" ) . ' <label for="' . $label . '">' . __( "Password:" ) . ' </label><input name="post_password" id="' . $label . '" type="password" size="20" /><input type="submit" name="Submit" value="' . esc_attr__( "Submit" ) . '" /> </form> '; return $o; } add_filter( 'the_password_form', 'my_password_form' ); ?> Quote Link to comment Share on other sites More sharing options...
requinix Posted August 1, 2013 Share Posted August 1, 2013 Thanks for mentioning you already had something with WordPress. Saved me the effort of having to write out something you won't use. I don't know WP. That form goes somewhere and will execute some code somewhere. That's where you should be looking for how to do this redirect thing. Quote Link to comment Share on other sites More sharing options...
Mr.Canuck Posted August 1, 2013 Author Share Posted August 1, 2013 Sorry, it wasn't intentional. I was going to use a custom script, but then I found where Wordpress had the code already and decided it would probably be easier to just use their already written code and modify it. I tried changing this line: $o = '<form class="protected-post-form" action="' . get_option( 'siteurl' ) . '/wp-login.php?action=postpass" method="post"> to this (wrote in the siteurl): $o = '<form class="protected-post-form" action="' . get_option( 'http://somewhere.com' ) . '/wp-login.php?action=postpass" method="post"> but it didn't work. Any idea why? Quote Link to comment Share on other sites More sharing options...
requinix Posted August 1, 2013 Share Posted August 1, 2013 (edited) Because you're making the form submit to that URL. As in that's where the data goes. You want it to stay on your site so you can verify the password, and if it's valid then you send them to the other site. [edit] Well, actually, I don't know what get_option() will do if you give it a URL instead of an option name. Probably return false/null/empty string. What you were trying to do should have been $o = ' Edited August 1, 2013 by requinix Quote Link to comment Share on other sites More sharing options...
Mr.Canuck Posted August 1, 2013 Author Share Posted August 1, 2013 Thank you. That worked Quote Link to comment Share on other sites More sharing options...
Mr.Canuck Posted August 1, 2013 Author Share Posted August 1, 2013 Oops, I jumped the gun. It redirects even if a wrong password or no password is entered. Can I just enter a default password somewhere in this script? Quote Link to comment Share on other sites More sharing options...
Mr.Canuck Posted August 1, 2013 Author Share Posted August 1, 2013 Here is the current code. It does direct me to "whatever.com" when I hit login, but it does that even if no password is entered. Is there a way to add a required default password in this script? <?php function my_password_form() { global $post; $label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID ); $o = '<form style="margin-left:250px" class="protected-post-form" action="http://whatever.com" method="post"> ' . __( "To enter AIS Cloud, please enter the username which was provided to you:" ) . ' <label for="' . $label . '">' . __( "Username:" ) . ' </label><input name="post_password" id="' . $label . '" type="password" size="20" /><input type="submit" name="Submit" value="' . esc_attr__( "Login" ) . '" /> </form> '; return $o; } add_filter( 'the_password_form', 'my_password_form' ); ?> Quote Link to comment Share on other sites More sharing options...
Mr.Canuck Posted August 2, 2013 Author Share Posted August 2, 2013 Seems as though I need to include the following in the action="" string: wp-login.php?action=postpass However, I can't seem to make it work with the URL in there as well (as this controls the password detection). I tried this: action="http://cloudnetcanada.com/index.php?Username=jaurora" '/wp-login.php?action=postpass' method="post" But it doesn't work. I'm sure the syntax is wrong (as I'm a PHP novice). Quote Link to comment 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.
× 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.