自动登录到字preSS仪表板从其他网站 [英] automatic login to wordpress dashboard from another site

查看:160
本文介绍了自动登录到字preSS仪表板从其他网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要自动登录WP管理员/从其他网站的仪表板没有去直通登录过程。我已经试过以下,但没有运气:

I want to log in automatically to WP admin/dashboard from another site without going thru the login process.. I've tried the following but with no luck:

<?php

$username="admin";
$password="mypasw";
$url="http://example.com/";
$cookie="cookie.txt";

$postdata = "log=". $username ."&pwd=". $password ."&wp-submit=Log%20In&redirect_to=". $url ."wp-admin/&testcookie=1";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url . "wp-login.php");
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_REFERER, $url . "wp-admin/");
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
curl_close($ch);
echo $result;
exit;


?>

这有点像只显示我的仪表板页面,但我真的不登录,因为点击管理页面上的任何按钮只重定向到这是网站页面相同的页面..:(

It's kind of like only showing me the dashboard page but I'm not really logged in since clicking on any buttons on the admin page is only redirecting to same page which is the site page.. :(

推荐答案

如果您访问的网站的,你试图登录的文件。您可以将用户名和密码,这个脚本添加一个自动登录PHP脚本和$ _ POST,例如:

If you have access to the files of the website where you trying to login. You could add a auto login php script and $_POST the username and password to this script, example:

if ($_POST) {

    $errors = array();

    $username = esc_sql($_REQUEST['username']);
    $password = esc_sql($_REQUEST['password']);
    $remember = esc_sql($_REQUEST['rememberme']);
    $remember = ($remember) ? "true" : "false";

    $login_data = array();
    $login_data['user_login'] = $username;
    $login_data['user_password'] = $password;
    $login_data['remember'] = $remember;
    $user_verify = wp_signon($login_data, true);

    if (is_wp_error($user_verify)) {
        $errors[] = 'Invalid username or password. Please try again!';
    } else {
        wp_set_auth_cookie($user_verify->ID);
        wp_redirect(admin_url());
        exit;
    }

}

字preSS codeX参考:

Wordpress codex references:


  • 登录功能:<一href=\"http://$c$cx.word$p$pss.org/Function_Reference/wp_signon\">http://$c$cx.word$p$pss.org/Function_Reference/wp_signon

  • 的管理员登录设置cookie的<一个href=\"http://$c$cx.word$p$pss.org/Function_Reference/wp_set_auth_cookie\">http://$c$cx.word$p$pss.org/Function_Reference/wp_set_auth_cookie

  • 获取的管理页面网址:<一href=\"http://$c$cx.word$p$pss.org/Function_Reference/admin_url\">http://$c$cx.word$p$pss.org/Function_Reference/admin_url

希望它帮助。

编辑: $ wpdb->逃跑是因为字preSS版本3.6 pcated德$ P $,WPDB使用:: prepare()或esc_sql()而不是!我已经改变了code使用esc_sql()。

$wpdb->escape is deprecated since Wordpress version 3.6, use wpdb::prepare() or esc_sql() instead! I've changed the code to use esc_sql().


  • esc_sql():<一href=\"http://$c$cx.word$p$pss.org/Function_Reference/esc_sql\">http://$c$cx.word$p$pss.org/Function_Reference/esc_sql

这篇关于自动登录到字preSS仪表板从其他网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆