-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.php
More file actions
137 lines (125 loc) · 5.25 KB
/
Copy pathdebug.php
File metadata and controls
137 lines (125 loc) · 5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
// debug_all.php — drop into your admin folder and open in browser
// WARNING: This file enables error display. Use only for debugging and remove afterwards.
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
// Basic header
echo "<!doctype html><html><head><meta charset='utf-8'><title>DEBUG — admin</title>";
echo "<style>body{font-family:Arial,Helvetica,sans-serif;background:#f7f9fb;color:#222;padding:20px} pre{background:#fff;border:1px solid #eee;padding:10px;overflow:auto} .ok{color:green} .bad{color:crimson}</style>";
echo "</head><body>";
echo "<h1>DEBUG — admin_reports</h1>";
echo "<p>Run this and paste the full page output back to me.</p>";
// PHP info (small)
echo "<h2>PHP Version & Environment</h2>";
echo "<pre>PHP_VERSION: " . PHP_VERSION . "\\nSAPI: " . PHP_SAPI . "</pre>";
// File list check
$files = ['functions.php','header.php','footer.php','admin_reports.php','api_admin_reports.php','assets/css/admin.css'];
echo "<h2>Check expected files in folder</h2><ul>";
foreach ($files as $f) {
$exists = file_exists($f) ? 'exists' : 'MISSING';
$size = $exists === 'exists' ? filesize($f) : 0;
echo "<li>" . htmlspecialchars($f) . ": ";
if ($exists === 'exists') {
echo "<span class='ok'>exists</span> — " . $size . " bytes";
} else {
echo "<span class='bad'>MISSING</span>";
}
echo "</li>";
}
echo "</ul>";
// Permissions of this file and folder
echo "<h2>Permissions</h2><pre>";
echo "__FILE__: " . __FILE__ . "\\n";
echo "file perms (octal): " . substr(sprintf('%o', fileperms(__FILE__)), -4) . "\\n";
echo "folder listing (first 30 files):\\n";
$li = array_slice(scandir(__DIR__), 0, 30);
foreach ($li as $name) {
if ($name === '.' || $name === '..') continue;
echo $name . " — " . (is_dir($name) ? 'dir' : filesize($name).' bytes') . "\\n";
}
echo "</pre>";
// Session / cookie info
echo "<h2>Session & Cookie</h2><pre>";
if (session_status() !== PHP_SESSION_ACTIVE) session_start();
echo "session_status: " . session_status() . "\\n";
echo "_SESSION: " . htmlspecialchars(var_export($_SESSION, true)) . "\\n";
echo "Cookies: " . htmlspecialchars(var_export($_COOKIE, true)) . "\\n";
echo "</pre>";
// Try to include functions.php safely (capture errors)
echo "<h2>Include functions.php (capture errors)</h2><pre>";
if (!file_exists('functions.php')) {
echo "functions.php is missing in this folder (expected filename: functions.php)\\n";
} else {
try {
ob_start();
include 'functions.php';
$out = ob_get_clean();
echo "Included functions.php successfully. Output length: " . strlen($out) . "\\n";
// check common functions
echo "Defined functions check:\\n";
echo "function_exists('get_user'): " . (function_exists('get_user') ? 'YES' : 'NO') . "\\n";
echo "function_exists('require_login'): " . (function_exists('require_login') ? 'YES' : 'NO') . "\\n";
if (function_exists('get_user')) {
try {
$u = @get_user();
echo \"get_user() returned: \" . htmlspecialchars(var_export($u, true)) . \"\\n\";
} catch (Throwable $e) {
echo \"get_user() threw: \" . $e->getMessage() . \"\\n\";
}
}
} catch (Throwable $e) {
ob_end_clean();
echo \"INCLUDE ERROR: \" . $e->getMessage() . \"\\n\";
}
}
echo "</pre>";
// Try including header.php/footer.php (but buffer output so we don't corrupt page)
echo "<h2>Include header.php / footer.php (buffered)</h2><pre>";
foreach (['header.php','footer.php'] as $hf) {
echo \"-- $hf --\\n\";
if (!file_exists($hf)) {
echo \"$hf is missing\\n\";
continue;
}
try {
ob_start();
include $hf;
$h_out = ob_get_clean();
echo \"$hf included (length: \" . strlen($h_out) . \")\\n\";
} catch (Throwable $e) {
ob_end_clean();
echo \"$hf include threw: \" . $e->getMessage() . \"\\n\";
}
}
echo "</pre>";
// Display last 100 lines of common php error logs if readable (best effort)
echo "<h2>Attempt to read common PHP/Apache error logs (best effort)</h2><pre>";
$paths = [
'/var/log/apache2/error.log',
'/var/log/httpd/error_log',
'/var/log/nginx/error.log',
'/var/log/php-errors.log',
'/var/log/php7.4-fpm.log',
'/var/log/php8.0-fpm.log'
];
foreach ($paths as $p) {
if (is_readable($p)) {
echo \"--- $p (last 100 lines) ---\\n\";
$lines = @file($p);
if ($lines) {
$tail = array_slice($lines, -100);
echo htmlspecialchars(implode('', $tail));
} else {
echo \"Could not read lines from $p\\n\";
}
echo \"\\n\\n\";
}
}
echo "If no logs found, check hosting panel for logs or ask host support.\\n";
echo "</pre>";
echo "<h2>Next steps</h2>";
echo "<ol><li>Paste the ENTIRE output of this page here (don't redact the error messages — you can remove secrets).</li>";
echo "<li>If the page is blank, check webserver error logs and paste the last 20 lines.</li></ol>";
echo "<hr><p style='color:#666;font-size:0.9em'>Remove debug_all.php when finished.</p>";
echo "</body></html>";