PHP Discord Webhooks aren’t sending on Debian VPS but are working on localhost?

  debian, discord, linux, php

So I just purchased a Debian based VPS and wanted to add some security features and track whenever a user logs onto the VPS and have a message sent to my discord server. So I used a PHP Webhook template and got it working on my local Linux Mint machine. Moved it over to VPS and the script runs but nothing shows in discord. Any ideas?

<?php
###############
#   Webhook   #
###############

$webhookurl = "Insert Hook Here";
$avatarurl = "https://i.imgur.com/FKtWYdX.png";
$title = "User Logged into VPS";
$user = file_get_contents('username');
$ip = file_get_contents('ip');

sendhook("Command_String's VPS Gate Keeper", $avatarurl, $title, $user, $ip, $webhookurl);

function sendhook($authorname, $avatarurl, $title, $user, $ip, $webhookurl){
$timestamp = date("c", strtotime("now"));

$json_data = json_encode([
    // Message
    "content" => "",
    
    // Username
    "username" => $authorname,

    // Avatar URL.
    "avatar_url" => $avatarurl,

    // Text-to-speech
    "tts" => false,

    // Embeds Array
    "embeds" => [
        [
            // Embed Title
            "title" => $title,

            // Embed Type
            "type" => "rich",

            // Embed Description
            #"description" => "Description",

            // URL of title link
            #"url" => "URL",

            // Timestamp of embed must be formatted as ISO8601
            "timestamp" => $timestamp,

            // Embed left border color in HEX
            "color" => hexdec( "3366ff" ),

            // Footer
            "footer" => [
                "text" => "",
            #    "icon_url" => "FooterIcon"
            ],

            // Author
            "author" => [
                "name" => $authorname,
            #    "url" => "AuthorURL"
            ],

            // Additional Fields array
            "fields" => [
                // Field 1
                [
                    "name" => "Who Logged?",
                    "value" => "$user",
                    "inline" => false
                ],
                // Field 2
                [
                    "name" => "From Where?",
                    "value" => "$ip",
                    "inline" => false
                ]
            ]
        ]
    ]

], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );


$ch = curl_init( $webhookurl );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $json_data);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec( $ch );
// If you need to debug, or find out why you can't send message uncomment line below, and execute script.
echo $response;
curl_close( $ch );}

Source: Ask PHP

LEAVE A COMMENT