#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    3
    Rep Power
    0
    Hi,
    If I want to write a user defined function that will be used in say 5 pages, how will the function file look and how will I include this file in a script on the pages?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 1999
    Location
    Denmark
    Posts
    83
    Rep Power
    15
    -- function.inc -----------------------
    <?
    function name_something($var1, $var2) {
    ...
    ...
    ...
    return $return_var;
    }
    ?>

    -- test.php ----------------------------
    <?
    include("function.inc");
    $my_var = name_something($var1, $var2);
    echo $my_var;
    ?>

    thats it..

    ------------------
    regds..
    -ulrik-
  4. #3
  5. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4492
    Note that .inc files are not usually parsed by your webserver. So if someone finds out the name of your include file and types it in, they will see a plain text version of your file. This might be okay for basic functions, but not for something that has a password in it. Either insure your webserver parses .inc files as PHP, or name them something like .inc.php, or place them outside of the web root and reference accordingly.

    ---John Holmes...

IMN logo majestic logo threadwatch logo seochat tools logo