Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Im using swish-e to index my corporate site and documents. Problem is that i need to login to wordpress via get variables. Wordpress login uses post variable but i need to login with GET variables

http://mysite.com/wp-login.php?log=username&pwd=password

There is any easy way to do it? I dont mind changing core files, is there is no other option.

I took a look at wp-login.php but i dont have a clue on how to do this.

Regards

share|improve this question
    
I highly doubt anyone here will give you advice to hack core files ... and wp-login.php looks at the $_POST object, not the $_REQUEST object ... so GET vars won't work without some hacking. Why don't you instead explain what it is you're trying to accomplish and we can give you a hand with that. –  EAMann Oct 26 '11 at 22:22
    
Im trying to login with GET vars :D . I use swish-e to index the whole site (including pdf and doc files) . This is a company site, so to view it you need to login. Swish-e supports login with get vars and direct http login but not via post. Thats basically my problem and thats why i dont mind to hack core files as the site is totally private –  chifliiiii Oct 26 '11 at 22:51
add comment

1 Answer

up vote 3 down vote accepted

Using GET variables for usernames and passwords is never a good idea. But anyway, something like the following should work

if(isset($_GET['log']) && isset($_GET['pwd'])){
    $creds = array();
    $creds['user_login'] = $_GET['log'];
    $creds['user_login'] = $_GET['pwd'];
    $creds['remember'] = true; //Do you want the log-in details to be remembered?

    $user = wp_signon( $creds, false );
    if ( is_wp_error($user) )
       echo $user->get_error_message(); //Display error message if log-in fails
}

You can put this in a template and then create a page using that template to create an alternative log-in page. In that case, you'll want to go to : http://[url of page]?log=username&pwd=password

To get http://mysite.com/wp-login.php?log=username&pwd=password, you will have to put the above code in the wp-login.php core file. Rather than adapting the code (which will be overwritten when you next update WordPress), I recommend using a hook. Like, so (put this in your functions.php or a plug-in):

add_action('init', 'GET_login');
function GET_login() {
    //Check that we are on the log-in page
    if(in_array($GLOBALS['pagenow'], array('wp-login.php'))):

    //Check that log and pwd are set
        if(isset($_GET['log']) && isset($_GET['pwd'])):
            $creds = array();
            $creds['user_login'] = $_GET['log'];
            $creds['user_password'] = $_GET['pwd'];
            $creds['remember'] = true; //Do you want the log-in details to be remembered?

            //Where do we go after log-in?
            $redirect_to = admin_url('profile.php');

            //Try logging in
            $user = wp_signon( $creds, false );

            if ( is_wp_error($user) ){
                //Log-in failed
            }else{
                //Logged in, now redirect
                $redirect_to = admin_url('profile.php');
                wp_safe_redirect($redirect_to);
            exit();
            }
        endif;
    endif;
    //If we are not on the log-in page or credentials are not set, carry on as normal
}

Explanation: Our function is run using init hook. It first checks that we are on the ./wp-login.php page, and then that the log and pwd variables are set. If not, we carry on as normal. If they are, we attempt a log-in, using wp_signon. If we are successful, we are redirected (wherever you like), otherwise if it fails, we do something (display errors, maybe?).

Hope that helps

share|improve this answer
    
You are a genius!!! Thanks for this great function. Never played before with custom login. I didnt know it was a hook that why i asked to hack core files, this its even better! +1 –  chifliiiii Oct 27 '11 at 0:09
    
Do you really want his login information to be indexed by a search engine??? WOW... NEVER LOGIN WITH GET or GOOGLE WILL "GET" YOU! –  EarnestoDev Oct 27 '11 at 1:35
    
+1 for using a filter rather than hacking core! @EarnestoDev He's trying to create an index for an internal site using a specific site indexing tool, not Google or a generic search engine. –  EAMann Oct 27 '11 at 16:01
    
@EAMann If he visits that GET login page with a browser with the Google Toolbar, he has all chances to get the logins indexed. Just a heads up. Only way to login with GET should be with IP specific hashes, not plain data. –  EarnestoDev Oct 27 '11 at 16:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.