Reputation: 17542
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
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
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:
public_html
. The best way to do this is either a class or a function that takes as parameters the arguments from your URL.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