Rushy Panchal
Rushy Panchal

Reputation: 17542

PHP - Send HTTP Request to local script

I'm trying to use one PHP script on my server that calls other scripts.

The main script, called call.php, is in the public_html folder, so I can send an HTTP request to it using my_website.com/call.php?action=some_script_name&arg1=value&arg2=some_other_value.

I already have a method to form the new request (and execute it), if the action script is in public_html. For example, if some_script.php was located at /public_html/scripts/some_script.php, my HTTP request would be my_website.com/scripts/some_script.php?arg1=value&arg2=some_other_value.

I have that done already, and it works correctly. However, I want to send requests to scripts that are NOT in public_html (or any subdirectory of that). For example, if I have a script under /lib/otherscript.php, I want to call that as well.

I tried a request such as ../lib/otherscript.php?args_here, but that did not work.

Is this possible, and if so, how can I accomplish this?

Edit:

The actual file structure of the (shared) server looks like this (for this example):

/
    public_html/
        call.php
        scripts/
            some_script.php

    lib/
        otherscript.php

Upvotes: 0

Views: 1060

Answers (2)

user1922137
user1922137

Reputation:

If you are using cPanel you can access php files outside public_html folder using absolute url, e.g.: <?php require_once('/home/username/lib/otherscript.php'); ?> now you can post parameters to any script within public_html folder at witch you have included otherscript.php.

Note: You have to use your cPanel user name in absolute address.

Upvotes: 1

elixenide
elixenide

Reputation: 44841

You can't access something outside public_html via HTTP; that's the whole point of the public_html directory. You have a few options:

  • Create a wrapper that is publicly accessible to call the functionality in public_html. The best way to do this is either a class or a function that takes as parameters the arguments from your URL.
  • Use the command line interpreter.

Either way, you may need to do some user authentication if the functionality is sensitive. If it's harmless, you can put it in public_html. If it's not, you need authentication/authorization checks.

Edited because I misread your question originally.

Upvotes: 1

Related Questions