Jump to content

password redirect to url


Mr.Canuck

Recommended Posts

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>
Link to comment
Share on other sites

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' );

?>
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 by requinix
Link to comment
Share on other sites

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' );

?>
Link to comment
Share on other sites

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).

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.