0

how can I invoke a php script on a remote server from my server code ?

I'm currently using:

header('Location: http://www.url.com/script.php?arg1=blabla');

in my code, but it doesn't work. thanks

3 Answers 3

2
  • If you mean by invoking just "calling" it, so you only need it to run, then you can use curl.

  • If you mean by invoking that you want it to act the same as include, then you can't trough http (the server does ofcourse not return code, but runs it). You might be able to obtain the file trough other means (ftp?), and then include it, but that seems like a bit of a hack.

  • If you mean by invoking that you want to redirect the user to the page, then this should work:

    header('Location: http://www.site.nl/');
    exit;

(your script continues to run after a header call, so you might need to call that exit). How doens't your code work for you? (I'm guessing because you want one of the other options)

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

4 Comments

Can I use curl just to call the script and pass arguments ? I don't need to get output back. I cannot find any example for my case
If they are get variables, you can just put them in the URL I presume
It is possible to "include" the contents of a remote script with PHP versions prior to 5.2 and with 5.2 onwards if allow_url_include is true. Seriously consider the security of doing this before implementing it though.
Yes, but mind this little gem from the manual: This is not strictly speaking the same thing as including the file and having it inherit the parent file's variable scope; the script is actually being run on the remote server and the result is then being included into the local script. ( php.net/manual/en/function.include.php )
1

If you only want to invoke the script you can simply use $result = file_get_contents('http://www.example.com/');. Your version using header() will as said above redirect the user.

Comments

0

Use cURL, it gives you much wider manipulation options.

Comments

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.