All web pages return http 500 not sure why

I’m sorry for how difficult this has been, but I refuse to believe that we cannot solve this issue here.

Looking at the most recent PHP code you shared, I’m very confused about that code. You wrap the code in PHP tags, but half of the code doesn’t look like valid PHP and seems more like Javascript.

I also don’t see or understand how this code is actually being used right now in your site. I see the fetch_sql.php script that’s being called in the background, but that only seems to fetch a track list, not the image.

I see some code in fetch_updater.js that seems to be related, but there seem to be multiple places that touch the image.


One ridiculously simple way to refresh the image is to just use this line in Javascript whenever you want to refresh the image:

document.getElementById("np_track_artwork").src = '/images/nowplaying_artwork_2.png?t='+Date.now();

What this code does is replace the image URL with a URL to the same image with a new timestamp generated in Javascript. This forces the browser to re-download the image (because the URL is different) resulting in the latest image being loaded.

No need to deal with any base64 stuff if you can just let the browser do the heavy lifting.

6 Likes

@Admin

Yes Admin but it was populating SQL from php push through

HIDDEN BY MOD - security

Now it wont do that a week later with no input from me or change, so why. you say its not simple, yes its a simple website , that push controls data up the java script it did two things before. It fetched the fetch_updater.js every 6000ms tested online image against the one on the server if it had changed by checking both base 64 of images (this prevents the thing hitting the server hard with refreshes all the time). it went and fetched new tracklist via checking in fetch_updater.js file from fetch_sql.php the Ajax command gets the content url in this case ‘/fetch_sql.php’ and places its content in t . now the xrm.Page code is Mircosoft code to place the text from t.responseText into the attribute arg on the page known as id ‘np_track_text’

new Ajax.Request(gContentUrl, {
            method: "get",onSuccess:function t() { 
                 Xrm.Page.getAttribute(arg).getValue(gUpdateDiv).innerHTML = t.responseText;  
            }
    });

this placed the text/html in fetch_sql.php into t_responseText and dumps it into attribute arg ie ‘np_track_text’ according to the debugger it does this fetch but does not reflect it on the page . The same is true of the artwork which is updated via the similar method: requesting the contents of the ID ‘outer_img’ but this time we don’t need it so use Microsoft again as direct id don’t work it seems anymore:

var  t_imageHTML = "<img id='np_track_artwork' src='http://www.deniserose.epizy.com/images/nowplaying_artwork_2.png?t="+$elapsed+"' alt='Playing track artwork' width=200 height=200>";
      new Ajax.Request('outer_img', {
          method: "get",onSuccess:function s() { 
                Xrm.Page.getAttribute(arg).getValue("outer_img").innerHTML = t_imageHTML; 
          }
      })

This also does not work as it did before on previous website not updating current open page

Hugs D

Eh… maybe I misunderstand how this works, but how does this help? To calculate the base64 of the image, you first need to download the image. So when you download the new version of the image, hasn’t the “damage” (in terms of hits, bandwidth) already been done?

OK, that pretty much matches with how I expected it to be intended.

The syntax is quite new to me though. I’ve never seen this Prototype Framework before. I personally would just go with the popular choice of jQuery, which is actually also included in the page.

Also, I’m having trouble finding where this Xrm.Page.getAttribute stuff is coming from. All results I see online refer to Microsoft Dynamics CRM, which doesn’t seem like you can just use that code in Javascript.


I debugged your code a bit and I see there is a syntax error in your Javascript here:

var image = document.createElement("#img999");

The createElement function takes the element name as input parameter. For an image, that’s img. The ID of the element can be specified later on.


If I understand it correctly, the setup should be as follows:

  1. Every 60 seconds, the /fetch_sql.php URL is called, which returns the tracks table as HTML
  2. The downloaded tracks table is injected into the page, replacing the contents of #np_track_text.
  3. The album art is refreshed with the latest image.

If so, I think your code can be simplified a lot. I think you can achieve the same results with this:

function CheckResponse(transport)
{
    // Replace the tracks table
    var content = transport.responseText;
    var table = document.getElementById("np_track_text");
    table.innerHtml = content;
    
    // Refresh the album art image
    var artwork = document.getElementById("np_track_artwork");
    artwork.src = "/images/nowplaying_artwork_2.png?t="+Date.now();
}

Functionally identical and much simpler!


I get that you want to avoid refreshing the image every minute because the image doesn’t always change. The problem is that in the current setup, the Javascript code doesn’t have any way to tell if the song playing now is the same song that was playing a minute ago (or not). The updater only gets a blob of HTML content and can’t really tell if the song was changed.

There are many different ways to solve that, but it either involves doing additional requests to the server (which kinda defeats the purpose - you might just as well download the image right away), or restructuring what’s already here.

Given how much trouble we seem to be having just getting the simple version to work, let’s leave the optimizations for now and keep it simple.

6 Likes

The problem is the add_track.php has decided not to inject sql after a week, with no error it just doesnt do it any more I haven been in it all week so remain confused . I put in your respose to try but nothing will happen s its not injeting to SQL

This is creating an object on page but off page this image was to load the image from the server not the page version to get its base64 ass i cant open it in jcript like i can or maybe cant in php on your server with fopen

I saw your updating main image still not working.
The solution is you need to push decay function to using delta time minimalize upto 30ms by using boolean variable.

I will try coding tomorrow. So tired today.
I see you tomorrow.

Thanks Edwin nothing will work my push to inject datas not working at all .


<?php
$servername = 
$username = 
$password = 
$dbname = 


//uses https://www.ascii-code.com/
function _clean($clean) {
$clean = utf8_encode($clean); 
$array_find =    array("è",      "ê",      "é",   "(" , ")" ,   "," , "#" ,  "'" , "@" , ";" , ":" , "&",".");
$array_replace = array("e","&ecirc","&eacute","(",")","","&#35","&#39","@","&#59","&#58","&","&#46");
$cleaned  = str_replace( $array_find,$array_replace, $clean);
return $cleaned;
}

function clean_Num($num_cl) {
 return str_replace(array( "0","1","2","3","4","5","6","7","8","9"),array("\x00","\x01","\x02","\x03","\x04","\x05","\x06","\x07","\x08","\x09"),$str);
   
}
/*$bpm = $_REQUEST['bpm'];
$length =$_REQUEST['len'];
$artist = $_REQUEST['artist'];
$artist= _clean($artist);
$title = $_REQUEST['title'];
$title= _clean($title);
$album = $_REQUEST['album'];
$album= _clean( $album);
$comment  =$_REQUEST['comment'];
$comment= _clean($comment);
*/

//MSQ 8.0
 $bpm = /*isset(*/$_REQUEST['bpm'];//) : throw new \InvalidArgumentException('value not set bpm.');
 $length = /*isset(*/$_REQUEST['len'];// : throw new \InvalidArgumentException('value not set len.');
 $artist = /*isset(*/$_REQUEST['artist'];//) : throw new \InvalidArgumentException('value not set artist.');
$artist= _clean($artist);
$title = /*isset(*/$_REQUEST['title'];//) : throw new \InvalidArgumentException('value not set title.');
$title= _clean($title);
$album = /*isset(*/$_REQUEST['album'];//) : throw new \InvalidArgumentException('value not set album.');
$album= _clean( $album);
$comment = $_REQUEST['comment'];
$comment= _clean($comment);
$genre= $_REQUEST['genre'];
$listeners =  $_REQUEST['listeners'];

// Does not cater for ' " / 3 & in input ' presently.


// note there is now num_rows  in PDO so we have to calculate.
try {
  $n = 0;    
  $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  $sql = "SELECT COUNT(`datetime`) FROM `played_songs` ORDER BY `datetime` ASC";
  $result = $conn->query($sql); // Use query as we are returning records.
  $row=$result->fetch();
  $n = $row["COUNT(`datetime`)"] - 150;
  if( $n >1) { $conn->exec("DELETE FROM `played_songs` LIMIT ".$n );}
  
} catch(PDOException $e) {
  echo $sql . "<br>" . $e->getMessage();
}
$conn = null;
//album cover
$artwork = isset($_REQUEST['artwork']) && ($_REQUEST['artwork'] !== '') ? $_REQUEST['artwork'] : false;
if ($artwork !== false) {
    $artwork = base64_decode($artwork);
    $r = fopen('images/nowplaying_artwork_2.png', 'wb');
    if ($r !== false) {
        fwrite($r, $artwork);
        fclose($r);
    } else 
        ReturnError(500, 'Failed to write artwork to a file.');{
        
    }
} else ReturnError(500, 'Failed to be provided artwork to write file.');
/*
$img = "http://www.deniserose.epizy.com/images/nowplaying_artwork_2.png?tr=w-200,h-200";
header('Content-Type: image/jpeg');
readfile($img);
$b64Data= base64_decode($img);
const byteCharacters = atob($b64Data);
const byteNumbers = array(byteCharacters.length);
for ($i=0; $i < byteCharacters.length; $i++) {
    byteNumbers[$i] = byteCharacters.charCodeAt($i);
}
const byteArray = new Uint8Array(byteNumbers);
const blob = new Blob(byteArray, { type: "text/html" });

imagedestroy($img);
*/

// Add record to database.
try {
  $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  $sql = "INSERT INTO `played_songs` (`song`, `artist`, `album`, `length`, `bpm`,`genre`, `listeners`,`track_user_rating`,`track_user_num`,`comment`) VALUES ('$title','$artist', '$album', '$length', '$bpm', '$genre','$listeners','0','0', '$comment')";
  $conn->exec($sql);
  echo "New record created successfully";
} catch(PDOException $e) {
   //echo $sql . "<br>" . $e->getMessage();
   ReturnError(500, "Failed to write record to SQL.".$e->getMessage());
}
//image.close();
$conn = null;



function ReturnError($code, $text) {
    $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
    header($protocol . ' ' . $code . ' ' . $text);
    exit();
}

?>

@Admin I simplified this for you but still does not inject data i removed database info it passes https://phpcodechecker.com/ with ‘No Issues Found’:

<?php
$servername = 
$username = 
$password = 
$dbname = 

//functions
//uses https://www.ascii-code.com/
function _clean($clean) {
$clean = utf8_encode($clean); 
$array_find =    array("è",      "ê",      "é",   "(" , ")" ,   "," , "#" ,  "'" , "@" , ";" , ":" , "&",".");
$array_replace = array("e","&ecirc","&eacute","(",")","","&#35","&#39","@","&#59","&#58","&","&#46");
$cleaned  = str_replace( $array_find,$array_replace, $clean);
return $cleaned;
}
function clean_Num($num_cl) {
 return str_replace(array( "0","1","2","3","4","5","6","7","8","9"),array("\x00","\x01","\x02","\x03","\x04","\x05","\x06","\x07","\x08","\x09"),$str);
   
}
//MSQ 8.0
$key = $_REQUEST['key'];
if($key != '^(((&__^') return;

$bpm = /*isset(*/$_REQUEST['bpm'];//) : throw new \InvalidArgumentException('value not set bpm.');
$length = /*isset(*/$_REQUEST['len'];// : throw new \InvalidArgumentException('value not set len.');
$artist = /*isset(*/$_REQUEST['artist'];//) : throw new \InvalidArgumentException('value not set artist.');
$artist= _clean($artist);
$title = /*isset(*/$_REQUEST['title'];//) : throw new \InvalidArgumentException('value not set title.');
$title= _clean($title);
$album = /*isset(*/$_REQUEST['album'];//) : throw new \InvalidArgumentException('value not set album.');
$album= _clean( $album);
$comment = $_REQUEST['comment'];
$comment= _clean($comment);
$genre= $_REQUEST['genre'];
$listeners =  $_REQUEST['listeners'];
$artwork = isset($_REQUEST['artwork']) && ($_REQUEST['artwork'] !== '') ? $_REQUEST['artwork'] : false;
//album cover
if ($artwork !== false) {
    $artwork = base64_decode($artwork);
    $r = fopen('images/nowplaying_artwork_2.png', 'wb');
    if ($r !== false) {
        fwrite($r, $artwork);
        fclose($r);
    } else 
        ReturnError(500, 'Failed to write artwork to a file.');{    
    }
} else ReturnError(500, 'Failed to be provided artwork to write file.');

// note there is now num_rows  in PDO so we have to calculate a new one to get record number.
try {
  $n = 0;    
  $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  $sql = "SELECT COUNT(`datetime`) FROM `played_songs` ORDER BY `datetime` ASC";
  $result = $conn->query($sql); // Use query as we are returning records.
  $row=$result->fetch();
  $n = $row["COUNT(`datetime`)"] - 150;
  if( $n >1) { $conn->exec("DELETE FROM `played_songs` LIMIT ".$n );}
  
} catch(PDOException $e) {
  echo $sql . "<br>" . $e->getMessage();
}
$conn = null;
// Add record to database.
try {
  $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  $sql = "INSERT INTO `played_songs` (`song`, `artist`, `album`, `length`, `bpm`,`genre`, `listeners`,`track_user_rating`,`track_user_num`,`comment`,`ImageBase64`) VALUES ('$title','$artist', '$album', '$length', '$bpm', '$genre','$listeners','0','0', '$comment',$artwork)";
  $conn->exec($sql);
  echo "New record created successfully";
} catch(PDOException $e) {
   //echo $sql . "<br>" . $e->getMessage();
   ReturnError(500, "Failed to write record to SQL.".$e->getMessage());
}
$conn = null;


function ReturnError($code, $text) {
    $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
    header($protocol . ' ' . $code . ' ' . $text);
    exit();
}

?>

oh dear , even my code to show error wont run

 function ReturnError($code, $text) {
    $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
    header($protocol . ' ' . $code . ' ' . $text);
    exit();
}

Yes, I understand how it’s supposed to work: you want to create a HTML tag from Javascript. But what you’re doing here is not valid Javascript.

The document.createElement function takes a HTML tag name. #img999 is not a valid HTML tag name. You can’t make a HTML element like <#img999></#img> so (at least in Firefox) the code simply crashes. If you want to create an image, the tag name must be img.

The function takes a HTML tag name. Not a query selector.

Linters and code checkers aren’t exhaustive. Just because code doesn’t contain syntax errors doesn’t mean it also does what you want it to do. Especially with dynamic languages like PHP it’s hard to say for certain if code works beforehand.

I see you’ve also added various echo statements throughout the code. You can only use the header function if no content has been sent yet to the browser, which is what happens with the echo statements.

This is likely causing your error handing code to crash.

Commenting out the header function and just echo-ing the error message is probably more resilient.

5 Likes

Well I think it was being blocked by a weird Microsoft Update dating from 2005 still investigating

Reduce the output volume (it’s currently under distortion)

btw. isn’t it more readable this way?

original

vs

/* Z E B R A      T A B L E */

.table-striped{background-color:#000}
tr:nth-child(even){background-color:#02f0cf75}

Better background colors could be found if you change the font color that is currently active,
because the current color of the text does not have enough contrast and does not match any background color).


As far as I could see, you are not using a “failsafe image” that would be displayed in the case of if there is no album art or something goes crazy in the process,
so think about that too.

4 Likes

I have

 var image = document.createElement("img");
    image.src = 'http://www.deniserose.epizy.com/images/nowplaying_artwork_2.png';
    image.name = 'img999';
    image.load();

Good to see the problems is clear understanding. Just need a view step to solve it.

it controlled by DSP there is auto-levelling on it I don’t have distortion from it turn your volume down :wink: unless you at neighbour to here it laughs.

What i do have is a connection issue with ionos somewhere at cust.te3-1.cr-4.rel.ncl.wildcard.net.uk [31.22.6.126] which times out posting data to you . I am on telephone to ISP as I write this

have you tried pressing play?
so listen to how the auto-level sounds

it’s not a problem that it’s loud but it’s distorted because the output is too strong

3 Likes

Its laughing at me press cross button bad kitten

can control volume at home. Sounds looks nice. good speaker make it great.
But i dont hear your music now. What happened.

I think it’s my fault (or someone else could hack)
because I visited this address and sent empty data (while I was trying something else).

image

4 Likes

aw. sounds terrible things. xD. How to fix it.
so have a good night everyone. See you tomorrow.