简体   繁体   中英

How do you make an IP Logger DiscordPHP Webhook

我将如何创建这样一个简单的脚本来完成该功能,我只是希望能够禁止/跟踪/阻止某些 Ips/位置访问我的网站,但我无法知道该位置是什么或者我只是想阻止某些 IP 访问我的网站,例如像 SpyBots 这样的东西:GoogleSpider 或 BingBOT。

Question is why would someone create such a thing? Simple answer is, so they can track the IPs coming into the website you host the DiscordPHP script on, simply to block/ban IPs and/or locations if you so wished.

Well here it is, the script you have been looking for. It is so simple and is commented so anyone that doesn't understand DiscordPHP->DiscordWebhook can see how and what does what :)

Feel free to modify this your needs, I wanted to give something to the community that has helped me in the past so.

<?php
//======PUT YOUR DISCORD WEBHOOK HERE (RECCOMENDED: MAKE THE CHANNEL SO YOU CAN SEE IT ONLY)========\\
$webhookurl = "https://discordapp.com/api/webhooks/WEBHOOK_ID/WEBHOOK_TOKEN";

//===========IP TO LOCATION & TIME/DATE INFORMATION PULLED BY THE HOSTING SERVER ====================\\
$ip = $_SERVER['REMOTE_ADDR'];
$browser = $_SERVER['HTTP_USER_AGENT'];
$TheirDate = date('d/m/Y');
$TheirTime = date('G:i:s');
$details = json_decode(file_get_contents("http://ip-api.com/json/{$ip}"));
$flag = "https://www.countryflags.io/{$details->countryCode}/shiny/64.png";
$data = "**User IP:** $ip\n**Date:** $TheirDate\n**Time:** $TheirTime \n**Location:** $details->city \n**Region:** $details->region\n**Country** $details->country\n**Postal Code:** $details->zip";




//=====================================DISCORD PHP BOT STUFF=========================================\\
$json_data = array ('content'=>"$data", 'username'=>"New Visitor From $details->country", 'avatar_url'=> "$flag");
$make_json = json_encode($json_data);
$ch = curl_init( $webhookurl );

//==================CURL OPTIONS FOR POSTING THE INFORMATION PROVIDED ABOVE ==========================\\
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $make_json);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

//===============THIS OUTPUTS THE CHANNEL SET BY THE WEBHOOK ==========================================\\
$response = curl_exec( $ch );

?>
$TheirTime = date('G:i:s');

应该

$TheirTime = time('G:i:s'); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM