0

I have a website on my computer on my localhost called testsite. Its on my apache localhost

so i can access a page http://localhost/testsite/index.php?p=763 from my browser.

index.php includes others php files. The index.php calls back and forth from many other php files in the folder.

so i went into the folder testsite and gave the command php index.php ?p=763

but it only shows the result of index.php but not with ?p=763 variable

Also i want to know when i run php index.php how to list all the php files it goes through (since there are various functions called from other files).

3 Answers 3

2

You could add the following at the beginning of your PHP script:

if (isset($argv[1]) && $argv[1][0] == '?') {
    parse_str(substr($argv[1], 1), $_GET);
}

It will automatically parse the argument that contains the query parameters and store them in the $_GET variable (thus making it as they came through a browser request).

Still, I wouldn't suggest relying on this approach. You should change your application so that it will handle command line arguments properly.

To see all files that were included you should use the get_included_files function at the end of your script:

print_r(get_included_files());
Sign up to request clarification or add additional context in comments.

4 Comments

what about listing all the php files it goes through
thats great. it showed all the files. Can i all get all the files list with how many times they are been called and for what function or values
in my index.php there is no $_GET variable, but it calls to some functions from difference php files which has that $_GET variable. but the number of functions it calls is huge, so how can i know here to put this code.
You should put the code at the top of your index.php file. The $_GET variable will be visible inside all of the included files. As for tracing all the calls, this is something that you should implement by yourself - you could probably use the debug_backtrace function but it really depends on what you are trying to achieve.
1

$_GET is only valid for page accessed using your browser. From console, inspect $argv. See https://stackoverflow.com/a/9612273/1349128

2 Comments

what about listing all the php files it goes through
You could call get_included_files() to get a list of included files.
0

If you do want to run a script on CLI that is designed for a web request you can cheat by setting the $_POST and $_GET variables manually from argv

See this post: http://edmondscommerce.github.io/php/running-php-scripts-on-cli-and-faking-a-web-request.html

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.