CustomApi not working

I’ve been trying to add a randomquote command using PHP.
When i run the command i get: [API must return less than 400 characters]
So far I managed to pin it down to fact that whenever the service is ran in an environment without javascript it generates this output:

 <html>
  <body>
    <script type="text/javascript" src="/aes.js" ></script>
    <script>function toNumbers(d){var e=[];d.replace(/(..)/g,function(d){e.push(parseInt(d,16))});return e}function toHex(){for(var d=[],d=1==arguments.length&&arguments[0].constructor==Array?arguments[0]:arguments,e="",f=0;f
      <d.length;f++)e+=(16>d[f]?"0":"")+d[f].toString(16);return e.toLowerCase()}var a=toNumbers("f655ba9d09a112d4968c63579db590b4"),b=toNumbers("98344c2eee86c3994890592585b49f80"),c=toNumbers("131b659496aad736a245ff451bf81764");document.cookie="__test="+toHex(slowAES.decrypt(c,2,a,b))+"; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/";location.href="http://mojd.byethost31.com/test.php?ckattempt=1";
      </script>
      <noscript>This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support</noscript>
    </body>
  </html>

However when I visit the link in my browser it returns a line of plain text(like it should).

any idea of what might have gone wrong?

Here is the php script:

<?php

$servername = "...";
$username = "...";
$password = "...";
$dbName = "...";
$indexId = "";
$newQuote = "";
$actionId = 0;

$conn = new mysqli($servername, $username, $password, $dbName);
if ($conn->connect_error) {
    die("Connection Failed: " . $conn->connect_error);
}
if ($actionId == 0) {
    $sqlQuery =  "SELECT id FROM Quotes";
    $result = $conn->query($sqlQuery);
    $max = $result->num_rows;
    if ($max > 0) {
        $rand = mt_rand(1, $max);
        $sqlQuery = "SELECT * FROM Quotes WHERE id =" . $rand;
        $result = $conn->query($sqlQuery);
        if ($result->num_rows > 0) {
            $output = $result->fetch_assoc();
            if (!empty($output)) {
                echo $output["quote"];
            }
            else {
                echo "outp.empty";
            }
        }
        else {
            echo "ERROR = result--" . $result->num_rows;
        }
    }
    else {
        echo "ERROR = max--" . $max;
    }

}
$conn->close();
	
?>

all help appreciated

Nightbot cannot parse JavaScript pages, so any output you generate must only be plaintext. When you view the source of your custom API, if it’s anything other than plaintext Nightbot will not parse it.

when i check my output it is set to output plain text but for some reason is doesn’t accept it as plain text

As was previously stated, you need to right click and view the source of the page. You’re printing an HTML page with JavaScript.

nowhere does my code print an html page, it only echo’s the result from the look up in the database or am i missing something?

If your web host is injecting HTML into every PHP page, then there’s nothing we can do about that. You’d need to reach out to them to find out why they are doing this.

i was thinking the same thing, i’ll have to look into that

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.