Test API Connection";
// Test 1: Cek koneksi ke server
echo "
1. Test Koneksi Server
";
$test_url = API_BASE . "login";
echo "URL: " . $test_url . "
";
$ch = curl_init($test_url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_TIMEOUT => 10,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
CURLOPT_POSTFIELDS => json_encode(['username' => 'test', 'password' => 'test'])
]);
$res = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
$info = curl_getinfo($ch);
curl_close($ch);
echo "HTTP Code: " . $httpCode . "
";
echo "Error: " . ($error ?: 'None') . "
";
echo "Response: " . htmlspecialchars($res) . "
";
echo "CURL Info: " . json_encode($info) . "
";
// Test 2: Cek dengan credentials yang mungkin benar
echo "2. Test dengan Credentials
";
$result = api_login('admin', 'admin');
echo "Result: " . json_encode($result, JSON_PRETTY_PRINT) . "
";
// Test 3: Cek dengan credentials kosong
echo "3. Test dengan Credentials Kosong
";
$result2 = api_login('', '');
echo "Result: " . json_encode($result2, JSON_PRETTY_PRINT) . "
";
// Test 4: Cek endpoint lain
echo "4. Test Endpoint Lain
";
$result3 = api_request('berita');
echo "Berita Result: " . json_encode($result3, JSON_PRETTY_PRINT) . "
";
echo "5. Cek Log Error PHP
";
echo "Error log location: " . ini_get('error_log') . "
";
echo "Log entries (last 10):
";
$log_entries = file_get_contents(ini_get('error_log'));
$lines = explode("\n", $log_entries);
$recent_lines = array_slice($lines, -10);
foreach ($recent_lines as $line) {
if (trim($line)) {
echo htmlspecialchars($line) . "
";
}
}