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

前端 未结 5 625
感动是毒
感动是毒 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 01:55

    cURL would primarily be used to retrieve data from external domains, therefore it wouldn't make too much sense to allow relative paths. The easiest thing to do would just be to append your current domain to the URL.

    $domain = $_SERVER['HTTP_HOST'] . "/";
    $ch = curl_init($domain . "b.php");
    echo(curl_exec($ch));
    curl_close($ch);
    

提交回复
热议问题