0

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
1
  • wait, is the lib folder outside of your apache documentroot? (assuming apache) Commented Mar 15, 2014 at 18:23

2 Answers 2

1

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.

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

3 Comments

Is it possible to call the script in another fashion, while also providing arguments?
Nope. You either put it in public_html or put something in public_html that invokes the functionality you want and passes appropriate arguments.
Note: @yaa110's answer is correct, but it's the same as my first bullet above. The point is that you can include a file outside public_html, but you can't access it directly via HTTP.
1

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.

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.