Custom File php and global function call

hi, I try to create a notification alert near the user icon.
in “page_foot” I insert this javascript that call a custom file created in phpmaker

<script type="text/javascript">
 function loadDoc() {
  setInterval(function(){

   var xhttp = new XMLHttpRequest();
   xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
     document.getElementById("noti_number").innerHTML = this.responseText;
    }
   };
   xhttp.open("GET", "noti.php", true);
   xhttp.send();

  },4000);
 }
 loadDoc();
</script>

the custom file “noti.php” is simple, call a php function in Global_code (all page)

<?php
namespace PHPMaker2021\project_n;
// Page object
$Noti = &$Page;
?>
<?php
notifiche();
?>
<?= GetDebugMessage() ?>

the function notifiche() is defined in global_code because use $_SESSION variable that I can see in custom file (i think)but appear this error. how to call a function that is in global_code?( ! ) Fatal error: Uncaught Error: Call to undefined function PHPMaker2021\project_n\notifiche();

I try to use $_SESSION in my custom file, but I receive the error that undefined $_SESSION name variable that I’m sure is set.
The custom file was create using “common file”.tks

I find a solution to display a notification near the user icon.In page_footI inserted this with the correct css:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

This call my custom file notifica.php:

<aside class="control-sidebar control-sidebar-light">
     <div class="p-3"></div>
 </aside>
<script type="text/html" class="ew-js-template" data-name="myControlSidebar" data-method="prependTo" data-target="#ew-navbar-right" data-seq="10">
    <li class="nav-item">
    
<table width="100%" style="color: white;">
 <tr width="75%">
  <td>
  </td>
  <td width="15%">
   <i class="fa fa-bell" aria-hidden="true" id="noti_number"></i>
  </td>
 </tr>
</table>
	</li>
</script>
<script type="text/javascript">
 function loadDoc() {
  setInterval(function(){
   var xhttp = new XMLHttpRequest();
   xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
     document.getElementById("noti_number").innerHTML = this.responseText;
    }
   };
   xhttp.open("GET", "notifica.php", true);
   xhttp.send();
  },4000);
 }
 loadDoc();
</script>

in notifica.php I have:

<?php
namespace PHPMaker2021\project_n;

// Page object
$Notifica = &$Page;
?>
<?php

if (session_id() == "") session_start(); // Init session data
ob_start(); // Turn on output buffering

$num_righe_pre=$_SESSION['num_richieste'];

$sqlr = "SELECT count(*) as ids from richiesta;";
$con=mysqli_connect("localhost","root","","mydbname");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
$result=mysqli_query($con,$sqlr);
$num_righe_arr = $result->fetch_assoc();
$num_righe_post=$num_righe_arr['ids'];

if ($num_righe_pre==0){
	$_SESSION['num_richieste']=$num_righe_post;
}else{
		if($num_righe_post>$num_righe_pre){
			echo $num_righe_post-$num_righe_pre;
		}else{
			echo "";
		}
}
?>

the session variable $_SESSION[‘num_richieste’] is set to 0 on list_page->page_rendering.
in this case I’m not using the auto-refresh on the page but inform the user about new record (the notification not work on delete record event but this is not my case)have you any suggestion about this simple solution? I found any difficult to read the Session variable because not used session_start before.
then I try to use executeScalar but appear an error because was not find.
tks

  1. It might be better to use Route_Action server event (or Api_Action server event) instead of Custom File to return data for Ajax.
  2. PHPMaker already includes Font Awesome (Free version), you do not need to include yourself.