php curl 自动登录,在PHP中使用CURL或fsockopen的WordPress自动登录

客户想要单击一个链接并自动登录到Wordpress后端管理部分.

我尝试使用fsockopen,代码如下.没工作.

$post_data['user_login'] = 'admin';

$post_data['user_pass'] = 'password';

$post_data['wp-submit'] = 'Log In';

$post_data['redirect_to'] = 'http://example.com/wp-admin/';

//traverse array and prepare data for posting (key1=value1)

foreach ( $post_data as $key => $value) {

$post_items[] = $key . '=' . $value;

}

//create the final string to be posted using implode()

$post_string = implode ('&', $post_items);

//we also need to add a question mark at the beginning of the string

$post_string = '?' . $post_string;

$data_length = strlen($post_string);

$connection = fsockopen('www.example.com', 80);

fputs($connection, "POST /wp-login.php HTTP/1.1\r\n");

fputs($connection, "Host: www.example.com \r\n");

fputs($connection, "Content-Type: application/x-www-form-urlencoded\r\n");

fputs($connection, "Content-Length: $data_length\r\n");

fputs($connection, "Connection: close\r\n\r\n");

fputs($connection, $post_string);

fclose($connection);

还试过CURL

$ch = curl_init('http://example.com/wp-login.php');

$post_data['user_login'] = 'admin';

$post_data['user_pass'] = 'password';

$post_data['wp-submit'] = 'Log In';

$post_data['redirect_to'] = 'http://example.com/wp-admin/';

//$post_data['testcookie'] = '0';

//$post_data['rememberme'] = 'forever';

foreach ( $post_data as $key => $value) {

$post_items[] = $key . '=' . $value;

}

//create the final string to be posted using implode()

$post_string = implode ('&', $post_items);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);

curl_exec ($ch);

curl_close ($ch);

任何人都有如何使这项工作的想法?

它是一个Linux操作系统.运行php5.

我之前使用javascript只是在页面加载时提交了一个包含所有隐藏输入的表单.客户端不需要javascript

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值