Click to See Complete Forum and Search --> : One function is called just by one script
amrigo
09-26-2008, 11:40 AM
Hi
I need that the function role_unassign() the resides on the file accesslib.php to be invoked only by the execution of the script enrol_database_sync.php.
It can be done ? how is it done ? http_referer or something like this ?
Thank´s in advance.
NogDog
09-26-2008, 12:58 PM
Is accesslib.php being included by enrol_database_sync.php, or is accesslib.php running by itself as a result of a form or link submission in enrol_database_sync.php?
amrigo
09-30-2008, 08:46 AM
Accesslib is included by the enrol/database/enrol_database_sync.php.
enrol_database_sync.php already has a check to not run by the browser:
if(!empty($_SERVER['GATEWAY_INTERFACE'])){
error_log("should not be called from apache!");
exit;
}
It is only called by the cron-job.
NogDog
09-30-2008, 12:04 PM
You could use get_included_files (http://www.php.net/get_included_files)(), e.g.:
if(in_array('enrol_database_sync.php', get_included_files())
{
// OK
}
else
{
// not allowed
}
This would not be a 100% sure thing, as it would return a true result if both files were separately included by a 3rd file. However, if enrol_database_sync.php will always be the main script, then I believe you could instead do:
$includes = get_included_files();
if($includes[0] == 'enrol_database_sync.php')
{
// OK
}
amrigo
10-01-2008, 07:00 AM
Hi
The role_unassign function os called by some others scripts (31) using get_included_files prevent the execution of the role_unassign function (that is defined at accesslib.php) and give exclusivity to enrol_database_sync.php to run this function ?
One idea was using getenv(SCRIPT_NAME) or script_filename but not sure about how it works.
Thank´s
amrigo
10-03-2008, 09:46 AM
You could use get_included_files (http://www.php.net/get_included_files)(), e.g.:
if(in_array('enrol_database_sync.php', get_included_files())
{
// OK
}
else
{
// not allowed
}
This would not be a 100% sure thing, as it would return a true result if both files were separately included by a 3rd file. However, if enrol_database_sync.php will always be the main script, then I believe you could instead do:
$includes = get_included_files();
if($includes[0] == 'enrol_database_sync.php')
{
// OK
}
Thank´s! enrol_database_sync.php is the main script it solves my problem.