在线调用php函数

在线调用php函数,php,api,function,include,Php,Api,Function,Include,我有一个问题,这件事是否可能 我遵循了以下设置: 一个服务器,它位于一个带有php园艺文件的服务器上,php在此文件上运行。现在我想在本地Web服务器上加载taget,然后调用函数 服务器: API.php 本地: test_locaal.php <?php include "http://***api.new*******.nl/API.php"; print_r(random_password()); ?> 我得到以下错误 致命错误:在第5行的E:\Webserver\ro

我有一个问题,这件事是否可能

我遵循了以下设置:

一个服务器,它位于一个带有php园艺文件的服务器上,php在此文件上运行。现在我想在本地Web服务器上加载taget,然后调用函数

服务器: API.php

本地: test_locaal.php

<?php

include "http://***api.new*******.nl/API.php";

print_r(random_password());
?>
我得到以下错误


致命错误:在第5行的E:\Webserver\root\API\test\u online.php中调用未定义的函数random\u password。这将导致PHP执行PHP代码并返回结果。但是您的api php文件不会返回任何输出

您可能想做的是通过url作为服务调用api。您的API应该作为服务器运行,接受请求并响应

网上有很多关于如何实现这一点的教程,也有很多库和框架

为了保持简单,你可以做另一件事。构造api并简单地调用提供所需输出的文件。i、 e:

api/random_password.php

本地:test_locaal.php

<?php

include "http://***api.new*******.nl/API.php";

print_r(random_password());
?>
当您将API.php包含为http URL时,服务器将执行它,然后返回其输出。在本例中,API.php的输出为空。因此,基本上,你不能在HTTP上包含一个远程php文件,除非你把它放在纯文本中,例如,将文件扩展名改为API.txt或类似的东西
<?php

$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$pass = array(); //remember to declare $pass as an array
$alpha_length = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < 8; $i++) {
  $n = rand(0, $alpha_length);
  $pass[] = $alphabet[$n];
}

echo json_encode(implode($pass)); //turn the array into a string and output it
<?php
$randomPassword = file_get_contents("http://***api.new*******.nl/api/random_password.php");

print_r($randomPassword);