我知道有很多这样的问题,但我找不到任何与我案件有关的具体细节。无论是那个还是他们没有得到答复。
我写了一个非常简单的PHP脚本并上传到zip文件夹中的wordPress站点,当我尝试激活插件时,WordPress给我一条消息:“插件无法激活,因为它触发了致命错误。”它实际上没有给我任何错误消息。我将WP_DEBUG,WP_DEBUG_LOG和WP_DEBUG_DISPLAY都设置为true,但这些都不会根据假定的错误更新。似乎我无法找出致命错误到底是什么。
我对如何处理这个问题感到很沮丧。任何帮助都会有用。
<?php
/*
Plugin Name: Denrile's Plogger
Plugin URI: http://my-awesomeness-emporium.com
description: >- a plugin to that takes the user to the Pruvan website,
after using CURL to log them in so that the redirect doesn't hit a user authentication wall.
Version: 1.0
Author: John Mauran
Author URI: http://github.com/jmauran91
License: GPL2
*/
$j_username = "Denrile";
$j_password = "*************";
$login_url ="https://titlereporter.direct.pruvan.com/v2/login";
$last_url = "https://titlereporter.direct.pruvan.com/v2/pmgr";
function loginToJulian($url, $username, $password){
$curl = curl_init();
$header[0]= "Accept: application/json, text/javascript, */*; q=0.01";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Content-Type: application/x-www-form-urlencoded";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$verbose = fopen(dirname(__FILE__).'/errorlog.txt', 'w');
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_STDERR, $verbose);
// Make the errors visible in a new file
$payload_username = '"'.$username.'"';
$payload_password = '"'.$password.'"';
$payloadtext=urlencode('{"username":'.$payload_username.',"password":'.$payload_password.'}');
$payload = "payload=".$payloadtext;
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
curl_setopt($curl, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$store = curl_exec($curl);
curl_close($store);
}
if(isset($_GET['prvn_login'])){
loginToJulian($login_url, $j_username, $j_password);
header("Location: https://titlereporter.direct.pruvan.com/v2/pmgr");
exit();
}
else{
exit();
}
?>
这个插件的一般想法是它将挂钩到wordPress网站上的javascript生成的A-tag,CURL Post到另一个站点登录,然后重新定向到该站点,希望绕过用户身份验证,因为用户将已经登录了,感谢CURL。
这段代码适合我。但有一个问题,为什么你添加了exit();在else条件下,它打破了插件激活过程。
请检查并让我知道。
<?php
/*
Plugin Name: Denrile's Plogger
Plugin URI: http://my-awesomeness-emporium.com
description: >- a plugin to that takes the user to the Pruvan website,
after using CURL to log them in so that the redirect doesn't hit a user authentication wall.
Version: 1.0
Author: John Mauran
Author URI: http://github.com/jmauran91
License: GPL2
*/
$j_username = "Denrile";
$j_password = "*************";
$login_url ="https://titlereporter.direct.pruvan.com/v2/login";
$last_url = "https://titlereporter.direct.pruvan.com/v2/pmgr";
function loginToJulian($url, $username, $password){
$curl = curl_init();
$header[0]= "Accept: application/json, text/javascript, */*; q=0.01";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Content-Type: application/x-www-form-urlencoded";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$verbose = fopen(dirname(__FILE__).'/errorlog.txt', 'w');
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_STDERR, $verbose);
// Make the errors visible in a new file
$payload_username = '"'.$username.'"';
$payload_password = '"'.$password.'"';
$payloadtext=urlencode('{"username":'.$payload_username.',"password":'.$payload_password.'}');
$payload = "payload=".$payloadtext;
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
curl_setopt($curl, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$store = curl_exec($curl);
curl_close($store);
}
function default_wordpress_hook(){
if(isset($_GET['prvn_login'])){
loginToJulian($login_url, $j_username, $j_password);
header("Location: https://titlereporter.direct.pruvan.com/v2/pmgr");
exit();
} else {
}
}
add_action("init","default_wordpress_hook");
?>