api - Call online php function -


i have question whether possible.

i have followed setup:

a server on server php horticultural file php functions on it. want taget load on local webserver , call function

server: api.php

<?php  function random_password() {      $alphabet = "abcdefghijklmnopqrstuwxyzabcdefghijklmnopqrstuwxyz0123456789";      $pass = array(); //remember declare $pass array      $alpha_length = strlen($alphabet) - 1; //put length -1 in cache      ($i = 0; $i < 8; $i++) {          $n = rand(0, $alpha_length);          $pass[] = $alphabet[$n];      }      return implode($pass); //turn array string  }  ?> 

local: test_locaal.php

<?php  include "http://***api.new*******.nl/api.php";  print_r(random_password()); ?> 

i following error

fatal error: call undefined function random_password() in e:\webserver\root\api\test_online.php on line 5

what including php file on http. leads php executing php code , returning result. api php file not return output.

what might want call api via url service. api should run server, accepting requests , answering response.

there quite few tutorials on web on how accomplish , there quite few libraries , frameworks well.

to keep simple thou, here's thing do. structure api , call file delivers output need. i.e.:

api/random_password.php

<?php  $alphabet = "abcdefghijklmnopqrstuwxyzabcdefghijklmnopqrstuwxyz0123456789"; $pass = array(); //remember declare $pass array $alpha_length = strlen($alphabet) - 1; //put length -1 in cache ($i = 0; $i < 8; $i++) {   $n = rand(0, $alpha_length);   $pass[] = $alphabet[$n]; }  echo json_encode(implode($pass)); //turn array string , output 

local: test_locaal.php

<?php $randompassword = file_get_contents("http://***api.new*******.nl/api/random_password.php");  print_r($randompassword); 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -