Saturday, 15 September 2012

php - How to know if a script was included inside another script -


I am new to PHP and it is very likely that I am using the wrong approach because I have not been used to think like a PHP programmer.

I have some files that include other files as dependencies, these files require a global code, which means some value in $ _ POST Includes something like

  if (isset ($ _ POST ["SomeValue"])) {/ * code goes here}  

all Files will be included in this code section, each one has its own code.

The problem is that since files can be included in one of these files, then the code section that I describe is executed in each included file, even when I Trowing AJAX posting clearly use the url of the script that I want to post.

I tried and guessed what script was used for the post, and even if it works because it was the correct script, it was the same script for ev include an ary file .

The question is:

  • Is there any way to know that the file is included in another file, so I can check for it and only that code Can I have the necessary values ​​in $ _ POST ?

Note : Files are generated using the Python script, which uses the own AC library, scans a database for its tables and constraints, C Library is mine as well as Python script, they work very well and if there is a fix for a file, then obviously it only needs to be done on Python scripts.

I tell the reader ( potential responder ) about this because I think it clarifies that I do not need a solution that works on files already present , Because they can happen again -

With its sounds you can completely avoid some improvements in your code structure. However, the information given to a simple flag variable should be trickled:

  if (sender ($ postCodeExecuted) and sender ($ _ POST ["SomeValue"])) * Code goes here * / $ postCodeExecuted = true; }  

This variable will be set in the global namespace and therefore it will be available from everywhere.


No comments:

Post a Comment