我正在制作一个记录暴力攻击的WordPress插件,但这是我的第二个插件,我不确定如何做到这一点。
我使用wp-admin
抓取强暴攻击guard_get_ip_address()
表单的计算机的IP。
但是现在我仍然坚持如何在用户进行暴力攻击时保存实际的IP。有没有办法将它保存到我在下面创建的表格中?
function logs() {
?>
<table>
<tr>
<th>IP</th>
</tr>
<tr>
<td><?php echo guard_get_ip_address(); ?></td>
</tr>
</table>
<?php
}
function add_logs() {
wp_add_dashboard_widget('dashboard_widget', 'Logs', 'logs');
}
add_action('wp_dashboard_setup', 'add_logs' );
编辑:函数guard_get_ip_address()
仅尝试获取IP;
function guard_get_ip_address() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
答案 0 :(得分:0)
//日志数据将存储在带有YOURFILENAME.DOC的文件夹中,用于打印该代码,并在您的视图页面中使用锚标签调用此功能
public function file_log()
{
$id = YOURFILENAME;
$file = APPPATH.'yourfile/'.$id.'.doc';
$content = file_get_contents($file);
echo '<html><body style="background-color:white; padding-
left:20px; padding-top:40px;">'.$content.'</body></html>';
}
//创建Base.php文件
function get_file_force_contents($contents,$LogfileName,$logUserName){
if($contents){
date_default_timezone_set("Asia/Kolkata");
$logtime = Date('d-M-Y h:i A');
$dir = APPPATH.'yourfile/';
@$file = $dir.'/'.$LogfileName.'.doc';
if(!is_dir($dir)) mkdir($dir, 0777, TRUE);
@$current = file_get_contents(@$file);
$current .= '<br>'.$logtime.' - '.'<strong>'.$logUserName.'</strong> - '.$contents;
file_put_contents($file, $current);
}
}
//控制器
require_once(APPPATH.'/Base.php');
function log{
$logUserName = 'logged in UserName';
$LogfileName = YourFILEName;
$LogData = json_decode($this->input->post('something1'), true);
$LogArray = array();
if(is_array($LogData)){
foreach($LogData as $key => $log){
foreach($log as $key1 =>$v){
$LogArray[$key1] = $v;
}
}
$array = array_unique($LogArray, SORT_REGULAR);
foreach ($array as $key => $value) {
$output = $value."<br>";
$contents = $output;
//print_r($contents);
get_file_force_contents($contents,$LogfileName,$logUserName);
}
}
}
//您的jquery代码 //用于输入更改开始
<script type="text/javascript">
var arr = [];
var InputPrevVal;
var InputCurrentVal;
$("input").on("focus",function () {
}).change(function() {
var InputID = $(this).attr('id');
var InputPrevVal = $('#'+InputID).attr('value');
var InputCurrentVal = $(this).val();
if(InputID == 'refrence_name'){
var ValueChangesForInput = 'Enquiry Person: ';
var value = $('#something').html('Updated '+ValueChangesForInput+' '+InputPrevVal+' To '+InputCurrentVal);
arr.push({Reference_Name:$('#something').val()});
}
$('#something1').val(JSON.stringify(arr));
//console.log('Input Changes : '+InputPrevVal+' To '+InputCurrentVal);
});
//用于下拉
var PreviousValue;
var SelectedIdChng;
$("select").on("focus",function () {
var SelectedId = $(this).attr("id");
var PreviousValue = $(this).attr("attr");
}).change(function() {
var SelectedIdChng = $(this).attr("id");
var CurrentValue = $(this).find("option:selected").text();
var PreviousValue = $(this).attr("attr");
if(SelectedIdChng == 'destination'){
var ValueChangesFor = 'Destination: ';
var value = $('#something').html('Updated '+ValueChangesFor+'
'+PreviousValue+' To '+CurrentValue);
arr.push({Destination:$('#something').val()});
}
console.log(arr);
$('#something1').val(JSON.stringify(arr));
});
</script>
//查看页面
<textarea id="something" name="something" class="" style="width:
1300px; height: 100px;">
</textarea>
<textarea id="something1" name="something1" class=""
style="width: 1300px; height: 100px;"></textarea>
<select name="destination" id="destination" required="" attr="At your
works/Door Delivery">
<option value="">Select</option>
<option value="1" selected="">At your works/Door Delivery</option>
<option value="2">At our works</option>
<option value="3">Godown Delivery</option>
</select>
<input type="text" class="form-control valid" name="refrence_name"
id="refrence_name" placeholder="refrence_name" value="Sonu Vishwakarma">
答案 1 :(得分:-1)
对不起,我误解了这个问题。
在您的插件中,您需要将服务器数据保存到javascript元素中,您可以在其中使用JQUERY来执行。目前我所知道的最快的方式是Cookies。
在PHP中创建一个cookie并将其拉入JS:
$ cookie_name =“IP”; $ cookie_value =“127.0.0.1”; //在这里添加你的价值 setcookie($ cookie_name,$ cookie_value,time()+(86400 * 30),“/”); // 86400 = 1天
var x = document.cookie;
,您可以使用JQUERY添加到表中:
$('tableid tr:first td')。html(x);