0

I am trying to keep my PHP code on one server, while calling the functions from a separate server.

Server 1

<?php
    echo 'Server 1';

    function testingStuff(){
        echo 'Testing Stuff';
    }

    function testingStuff2(){
        return "Testing Stuff 2";
    }
?>

Server 2

<?php
    include 'fullURLtoServer1.php';

    testingStuff();

    echo testingStuff2();
?>

I know the include statement is working, as "Server 1" is being properly echoed to the screen, but neither of the function calls displays anything. Am I missing something? Why do neither function calls work?

EDIT 1

The ideal situation would be having a single .php file on Server 1 that contains multiple functions, which I can call as often as I'd like.

5

1 Answer 1

0

When you "include" a remote file, you are included the output of that file.

For server 2, the file you are trying to include just says:

Server 1

If you want to execute remote functions, you can make a different file for each function, and execute the function when the file is called. That way, you can "include" the remote file and show the output. You can replace the "different file for each function" for a single file with a parameter.

Keep in mind, trough, that any user/server/bot can call those functions by simply loading the file from the webserver.

Sign up to request clarification or add additional context in comments.

2 Comments

So there isn't a way that I can have a single .php file on my server with multiple functions in it? Some requiring parameters, others not. And then call the functions as often as required?
@Birrel If they are in separate servers, you can't use them using the HTTP protocol, as PHP would process them in calling time. You may, for example, output the whole "php" file, but the code would be visible for any with remote access to that file, and the code will be executed in Server 1, not server 2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.