Is it possible to use curl with relative path in PHP?

前端 未结 5 620
感动是毒
感动是毒 2020-12-11 01:35

I have two php pages. I want to fetch b.php in a.php.

In my a.php:

$ch = curl_init(\"b.php\");
echo(curl_exec($ch));
curl_close($ch);
5条回答
  •  青春惊慌失措
    2020-12-11 02:14

    How about taking the domain from HTTP_HOST?

    $domain = $_SERVER['HTTP_HOST'];
    $prefix = $_SERVER['HTTPS'] ? 'https://' : 'http://';
    $relative = '/b.php';
    $ch = curl_init($prefix.$domain.$relative);
    echo(curl_exec($ch));
    curl_close($ch);
    

提交回复
热议问题