Base Directory:
/home/ecedu/public_html/new/ckad
$file) {
$postData[$key] = new CURLFile($file['tmp_name'], $file['type'], $file['name']);
}
}
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
}
$response = curl_exec($ch);
if ($response === false) {
http_response_code(500);
die("خطأ في الاتصال بالخادم: " . curl_error($ch));
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headersRaw = substr($response, 0, $headerSize);
$body = substr($response, $headerSize);
curl_close($ch);
// معالجة Redirect
if (in_array($httpCode, [301,302,303,307,308])) {
if (preg_match('/Location:\s*(.+)/i', $headersRaw, $matches)) {
$location = trim($matches[1]);
$redirectPage = basename(parse_url($location, PHP_URL_PATH));
if (in_array($redirectPage, $allowedPages)) {
header("Location: ?page=" . urlencode($redirectPage));
exit;
} else {
http_response_code(403);
die("إعادة توجيه غير مصرح بها");
}
}
}
// إعادة إرسال رؤوس مهمة مثل Set-Cookie و Content-Type
foreach (explode("\n", $headersRaw) as $header) {
if (stripos($header, 'Content-Type:') === 0 || stripos($header, 'Set-Cookie:') === 0) {
header(trim($header));
}
}
// تعديل روابط HTML لجعلها تمر عبر البروكسي (href, src, action)
if (stripos($headersRaw, 'Content-Type: text/html') !== false) {
$body = preg_replace_callback('/(href|src|action)\s*=\s*([\'"])(.*?)\2/i', function ($matches) use ($allowedPages) {
$attr = $matches[1];
$quote = $matches[2];
$url = $matches[3];
if (preg_match('/^(https?:)?\/\//i', $url) || strpos($url, 'mailto:') === 0) {
return $matches[0];
}
$cleanUrl = ltrim(parse_url($url, PHP_URL_PATH) ?? '', '/\\');
if (in_array($cleanUrl, $allowedPages)) {
return "$attr=$quote?page=" . urlencode($cleanUrl) . "$quote";
}
return $matches[0];
}, $body);
}
echo $body;