<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);
if (!extension_loaded('curl')) {
die('CRITICAL: CURL is missing!');
}
set_time_limit(0);
function h($value): string
{
return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
}
function parseHeaderLines(string $raw): array
{
$lines = preg_split('/rn|r|n/', $raw);
$headers = [];
foreach ($lines as $line) {
$line = trim($line);
if ($line === '') { continue;
}
if (strpos($line, ':') === false) {
continue;
}
$headers[] = $line;
}
return $headers;
}
function parseFormLines(string $raw): array
{
$lines = preg_split('/rn|r|n/', $raw);
$data = [];
foreach ($lines as $line) {
$line = trim($line);
if ($line === '') {
continue;
}
$parts = explode('=', $line, 2);
$key = trim($parts[0]);
$value = isset($parts[1]) ? trim($parts[1]) : '';
if ($key !== '') {
$data[$key] = $value;
}
}
return $data;
}
function hasHeader(array $headers, string $needle): bool
{
foreach ($headers as $header) {
if (stripos($header, $needle . ':') === 0) {
return true;
}
}
return false;
}
function sendRequest(array $input): array
{
$url = trim($input['url'] ?? '');
$method = strtoupper(trim($input['method'] ?? 'GET'));
$params = parseFormLines((string)($input['params'] ?? ''));
$rawBody = (string)($input['raw_body'] ?? '');
$cookies = trim((string)($input['cookies'] ?? ''));
$headers = parseHeaderLines((string)($input['headers'] ?? ''));
$connectTimeout = max(1, (int)($input['connect_timeout'] ?? 10));
$timeout = max($connectTimeout, (int)($input['timeout'] ?? 30)); $verifySsl = !empty($input['verify_ssl']);
if ($url === '') {
throw new InvalidArgumentException('URL gerekli.');
}
if (session_status() === PHP_SESSION_ACTIVE) {
session_write_close();
}
$bodyString = '';
$requestUrl = $url;
if ($method === 'GET') {
if (!empty($params)) {
$query = http_build_query($params);
$requestUrl .= (strpos($requestUrl, '?') !== false ? '&' : '?') . $query;
}
} else {
if ($rawBody !== '') {
$bodyString = $rawBody;
} elseif (!empty($params)) {
$bodyString = http_build_query($params);
if (!hasHeader($headers, 'Content-Type')) {
$headers[] = 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8';
}
}
}
// POST/PUT/PATCH/DELETE tarafında bazı sunucularda 100-continue takılmasını engeller
if (!hasHeader($headers, 'Expect')) {
$headers[] = 'Expect:';
}
if (!hasHeader($headers, 'Connection')) {
$headers[] = 'Connection: close';
}
if (!hasHeader($headers, 'User-Agent')) {
$headers[] = 'User-Agent: PHP Request Debugger/1.0';
}
if ($bodyString !== '' && !hasHeader($headers, 'Content-Length')) {
$headers[] = 'Content-Length: ' . strlen($bodyString);
}
$ch = curl_init();
$options = [
CURLOPT_URL => $requestUrl,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 5,
CURLOPT_CONNECTTIMEOUT => $connectTimeout,
CURLOPT_TIMEOUT => $timeout,
CURLOPT_ENCODING => '',
CURLOPT_NOSIGNAL => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_SSL_VERIFYPEER => $verifySsl,
CURLOPT_SSL_VERIFYHOST => $verifySsl ? 2 : 0,
CURLOPT_COOKIE => $cookies,
CURLOPT_HTTPHEADER => $headers, ];
switch ($method) {
case 'GET':
$options[CURLOPT_HTTPGET] = true;
break;
case 'POST':
$options[CURLOPT_POST] = true;
$options[CURLOPT_POSTFIELDS] = $bodyString;
break;
case 'HEAD':
$options[CURLOPT_NOBODY] = true;
$options[CURLOPT_CUSTOMREQUEST] = 'HEAD';
break;
default:
$options[CURLOPT_CUSTOMREQUEST] = $method;
$options[CURLOPT_POSTFIELDS] = $bodyString;
break;
}
curl_setopt_array($ch, $options);
$rawResponse = curl_exec($ch);
$errno = curl_errno($ch);
$error = curl_error($ch);
$info = curl_getinfo($ch);
if ($rawResponse === false) {
$rawResponse = '';
}
$headerSize = $info['header_size'] ?? 0; $responseHeaders = substr($rawResponse, 0, $headerSize);
$responseBody = substr($rawResponse, $headerSize);
curl_close($ch);
return [
'request_url' => $requestUrl,
'method' => $method,
'request_headers' => $headers,
'request_body' => $bodyString,
'errno' => $errno,
'error' => $error,
'info' => $info,
'response_headers' => $responseHeaders,
'response_body' => $responseBody,
];
}
$result = null;
$exceptionMessage = null;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
try {
$result = sendRequest($_POST);
} catch (Throwable $e) {
$exceptionMessage = $e->getMessage();
}
}
?>
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<title>PHP Request Debugger</title>
<style>
:root {
--bg: #0d1117;
--card: #161b22;
--border: #30363d;
--blue: #58a6ff;
--green: #2ea043;
--red: #f85149;
--text: #c9d1d9;
--muted: #8b949e;
}
* { box-sizing: border-box; }
body {
margin: 0;
padding: 24px;
background: var(--bg);
color: var(--text);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.box {
background: var(--card);
border: 1px solid var(--border);
border-radius: 10px;
padding: 20px;
margin-bottom: 18px;
}
h1, h2 {
margin-top: 0;
color: var(--blue);
}
.grid {
display: grid;
gap: 14px;
}
.grid-2 {
grid-template-columns: 2fr 1fr;
}
.grid-3 {
grid-template-columns: repeat(3, 1fr);
}
label {
display: block;
margin-bottom: 6px;
font-size: 13px;
color: var(--muted);
}
input, select, textarea, button {
width: 100%;
border-radius: 8px;
border: 1px solid var(--border);
background: #0d1117;
color: #fff;
padding: 12px;
font-size: 14px;
}
textarea {
min-height: 140px;
resize: vertical;
font-family: Consolas, monospace;
}
button {
background: var(--green);
border: none;
font-weight: 700;
cursor: pointer;
}
pre {
white-space: pre-wrap;
word-break: break-word;
background: #0b0f14;
border: 1px solid var(--border);
padding: 14px;
border-radius: 8px;
overflow: auto; }
.meta {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 12px;
}
.meta .item {
background: #0b0f14;
border: 1px solid var(--border);
border-radius: 8px;
padding: 12px;
}
.k {
color: var(--muted);
font-size: 12px;
display: block;
margin-bottom: 4px;
}
.v {
font-weight: 700;
}
.error {
color: #fff;
background: rgba(248, 81, 73, 0.15);
border: 1px solid rgba(248, 81, 73, 0.4);
padding: 12px;
border-radius: 8px;
}
.ok {
color: #fff;
background: rgba(46, 160, 67, 0.15);
border: 1px solid rgba(46, 160, 67, 0.4);
padding: 12px;
border-radius: 8px;
}
</style>
</head> <body>
<div class="box">
<h1>PHP Request Debugger</h1>
<form method="POST">
<div class="grid grid-2">
<div>
<label>URL</label>
<input
type="text"
name="url"
value="<?= h($_POST['url'] ?? '') ?>"
placeholder="https://example.com/api/test"
required
>
</div>
<div>
<label>Method</label>
<select name="method">
<?php
$methods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD'];
$currentMethod = strtoupper($_POST['method'] ?? 'GET');
foreach ($methods as $m) {
$sel = $currentMethod === $m ? 'selected' : '';
echo '<option ' . $sel . '>' . h($m) . '</option>';
}
?>
</select>
</div>
</div>
<div class="grid grid-3" style="margin-top:14px;">
<div>
<label>Connect Timeout (sn)</label>
<input type="number" name="connect_timeout" value="<?= h($_POST['connect_timeout'] ?? '10') ?>" min="1">
</div>
<div>
<label>Total Timeout (sn)</label>
<input type="number" name="timeout" value="<?= h($_POST['timeout'] ?? '30') ?>" min="1">
</div>
<div>
<label>Cookies</label>
<input type="text" name="cookies" value="<?= h($_POST['cookies'] ?? '') ?>" placeholder="session=abc123; foo=bar">
</div>
</div>
<div class="grid grid-2" style="margin-top:14px;">
<div>
<label>Form Params (satır başına key=value)</label>
<textarea name="params" placeholder="name=ali
email=ali@example.com"><?= h($_POST['params'] ?? '') ?></textarea>
</div>
<div>
<label>Raw Body</label>
<textarea name="raw_body" placeholder='{"name":"ali"}'><?= h($_POST['raw_body'] ?? '') ?></textarea>
</div>
</div>
<div style="margin-top:14px;">
<label>Headers (satır başına Header: value)</label>
<textarea name="headers" placeholder="Accept: application/json
X-Test: 1"><?= h($_POST['headers'] ?? '') ?></textarea>
</div>
<div style="margin-top:14px; margin-bottom:14px;">
<label>
<input type="checkbox" name="verify_ssl" value="1" <?= !empty($_POST['verify_ssl']) ? 'checked' : '' ?> style="width:auto; margin-right:8px;">
SSL doğrulaması açık
</label>
</div>
<button type="submit">İsteği Gönder</button>
</form>
</div>
<?php if ($exceptionMessage !== null): ?>
<div class="box">
<div class="error"><?= h($exceptionMessage) ?></div>
</div>
<?php endif; ?>
<?php if ($result !== null): ?>
<div class="box">
<h2>Özet</h2>
<?php if ($result['errno'] !== 0): ?>
<div class="error">
<strong>cURL Error #<?= h($result['errno']) ?>:</strong>
<?= h($result['error']) ?>
</div>
<?php else: ?>
<div class="ok">İstek tamamlandı.</div>
<?php endif; ?>
<div class="meta" style="margin-top:14px;">
<div class="item">
<span class="k">HTTP Code</span>
<span class="v"><?= h($result['info']['http_code'] ?? 0) ?></span>
</div>
<div class="item">
<span class="k">Total Time</span>
<span class="v"><?= h($result['info']['total_time'] ?? 0) ?> sn</span>
</div>
<div class="item">
<span class="k">Connect Time</span>
<span class="v"><?= h($result['info']['connect_time'] ?? 0) ?> sn</span>
</div>
<div class="item">
<span class="k">Redirect Count</span>
<span class="v"><?= h($result['info']['redirect_count'] ?? 0) ?></span>
</div>
</div>
</div>
<div class="box">
<h2>Request</h2>
<pre><?= h($result['method'] . ' ' . $result['request_url']) . "nn" .
h(implode("n", $result['request_headers'])) . "nn" .
h($result['request_body']) ?></pre>
</div>
<div class="box">
<h2>Response Headers</h2>
<pre><?= h($result['response_headers']) ?></pre>
</div>
<div class="box">
<h2>Response Body</h2>
<pre><?= h($result['response_body']) ?></pre>
</div>
<div class="box">
<h2>cURL Info</h2>
<pre><?= h(print_r($result['info'], true)) ?></pre>
</div>
<?php endif; ?>
</body>
</html>