Panel/backup-website/diag_remote.php

72 lines
3.2 KiB
PHP

<?php
// Remote diagnostic helper for GameServers.World (_website)
// Upload this file to the remote server and open it in the browser to collect environment info.
header('Content-Type: text/plain; charset=utf-8');
echo "GSP _website remote diagnostic\n";
echo "Date: " . date('c') . "\n\n";
// PHP info summary
echo "PHP Version: " . PHP_VERSION . "\n";
echo "Loaded extensions: " . implode(', ', get_loaded_extensions()) . "\n\n";
// Session settings
echo "Session save path: " . (ini_get('session.save_path') ?: '(not set)') . "\n";
echo "Session cookie params: " . json_encode(session_get_cookie_params()) . "\n";
echo "Session status (before start): " . session_status() . "\n";
// Try to start a named session used by _website
session_name('gameservers_website');
@session_start();
echo "Session status (after start): " . session_status() . "\n";
echo "Session id: " . session_id() . "\n";
echo "Session variables: \n" . print_r($_SESSION, true) . "\n";
// Check config file readability
$cfg = __DIR__ . '/includes/config.inc.php';
echo "Config file: " . $cfg . " exists=" . (file_exists($cfg) ? 'yes' : 'no') . " readable=" . (is_readable($cfg) ? 'yes' : 'no') . "\n";
if (file_exists($cfg)) {
echo "Config contents (first 200 chars):\n" . substr(file_get_contents($cfg),0,200) . "\n";
}
// Attempt DB connection using site config (if readable)
if (file_exists($cfg)) require_once($cfg);
echo "Trying DB connection...\n";
$ok = false;
if (isset($db_host)) {
$db = @mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if ($db) {
echo "DB connect: OK (host=$db_host db=$db_name)\n";
$ok = true;
// run a small query
$q = @mysqli_query($db, "SELECT COUNT(*) AS cnt FROM information_schema.tables WHERE table_schema = '".mysqli_real_escape_string($db,$db_name)."'");
if ($q) {
$r = mysqli_fetch_assoc($q);
echo "Tables in DB: " . ($r['cnt'] ?? 'unknown') . "\n";
}
mysqli_close($db);
} else {
echo "DB connect: FAILED (mysqli_connect_error: " . mysqli_connect_error() . ")\n";
}
} else {
echo "DB config not available to attempt connection.\n";
}
// Check data and logs directories
$data = realpath(__DIR__ . '/..') . DIRECTORY_SEPARATOR . 'data';
$logs = __DIR__ . DIRECTORY_SEPARATOR . 'logs';
echo "Site data dir: $data exists=" . (is_dir($data)?'yes':'no') . " writable=" . (is_writable($data)?'yes':'no') . "\n";
echo "Site logs dir: $logs exists=" . (is_dir($logs)?'yes':'no') . " writable=" . (is_writable($logs)?'yes':'no') . "\n";
// Try creating test files
if (is_dir($logs) && is_writable($logs)) {
$fn = $logs . DIRECTORY_SEPARATOR . date('Y-m-d') . '.diag.txt';
$w = @file_put_contents($fn, "diag " . date('c') . "\n", FILE_APPEND);
echo "Wrote diag file to $fn result=" . ($w ? 'ok' : 'fail') . "\n";
}
echo "\nSuggested next checks:\n";
echo " - Confirm PHP can write session files to session.save_path and that cookies are sent to browser (use browser devtools).\n";
echo " - Ensure the site path is served under the expected /_website/ path and that session cookie domain/path match the served path.\n";
echo " - If sessions aren't persistent across requests, check webserver user permissions and session.save_path.\n";
?>