To hide my code in source view, I tried this way: I splitted variabili.inc (with mixed php variable and js) in two files:
file1.inc
<?php
$root=".";
include "$root/definiz_siti.inc";
header('Content-Type: application/json');
echo json_encode([
'base_url' => $root,
'base_url_etexts' => $etexts,
'base_url_fede' => $xmo,
'base_url_mondo' => $mondooggi,
'intellectualia' => $intellectualia,
]);
?>
file2.js (same, root, folder)
$.ajax({
type: 'GET',
url: 'file1inc',
dataType: 'json',
success: function(data) {
var base_url = data.base_url;
var base_url_etexts = data.base_url_etexts;
var base_url_fede = data.base_url_fede;
var base_url_mondo = data.base_url_mondo;
var intellectualia = data.intellectualia;
console.log('Dati ricevuti:', data);
// Utilizza i valori per caricare i contenuti
$( "#pelag" ).load(base_url + "/glossario.php #pelagianesimo" ); //in qualsiasi folder
$( "#gratia" ).load(base_url + "/glossario.php #grazia" ); //in qualsiasi folder
// etexts di filosofi
$( "#etexts_aristotele" ).load(base_url_etexts + "/filosofi/antichi/index.php #etexts_aristotele" );
$( "#etexts_Bruno" ).load(base_url_etexts + "/filosofi/moderni/index.php #etexts_Bruno" );
// etexts letterari
$( "#etexts_Virgilio" ).load(base_url_etexts + "/letteratura/0.antica/index.php #etexts_Virgilio" $( "#etexts_Hopkins" ).load(base_url_etexts + "/letteratura/3.800/index.php #etexts_Hopkins" );
// etexts religiosi
$( "#etexts_bibbia" ).load(base_url_etexts + "/religiosi/index.php #etexts_bibbia" );
}
});
In any footer of php files file2 is called:
<script src=\"$root/file2.js\" defer=\"defer\"></script>";
But this new way doesnât work (and AI didnât help ): no output.
Opening file1.inc in a browser (in local root folder) this is the output:
$root, 'base_url_etexts' => $etexts, 'base_url_fede' => $xmo, 'base_url_mondo' => $mondooggi, 'intellectualia' => $intellectualia, ]); ?>
EDIT
In php sandbox I get this error
Warning: Undefined array key "SERVER_NAME" in /home/user/scripts/code.php on line 3
line 3 (in âdefiniz_siti.incâ) is this:
if ($_SERVER['SERVER_NAME'] === "localhost")