www.webdeveloper.com
Results 1 to 6 of 6

Thread: One function is called just by one script

  1. #1
    Join Date
    Feb 2004
    Location
    Brasil porto Aelgre
    Posts
    544

    One function is called just by one script

    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.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,224
    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?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Feb 2004
    Location
    Brasil porto Aelgre
    Posts
    544
    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.

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,224
    You could use get_included_files(), e.g.:
    PHP Code:
    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:
    PHP Code:
    $includes get_included_files();
    if(
    $includes[0] == 'enrol_database_sync.php')
    {
       
    // OK

    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Feb 2004
    Location
    Brasil porto Aelgre
    Posts
    544
    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

  6. #6
    Join Date
    Feb 2004
    Location
    Brasil porto Aelgre
    Posts
    544
    Quote Originally Posted by NogDog View Post
    You could use get_included_files(), e.g.:
    PHP Code:
    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:
    PHP Code:
    $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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles