1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

problem with functions on include files

Discussion in 'PHP' started by mahmood, Mar 25, 2006.

  1. #1
    I have a problem with include files and I am not sure if they are supposed to be like this or not.

    Briefly it seems that I can include an external php file but I cannot call a function on that file.

    for example:

    <? include "myFile.php"; myFunction();
    PHP:
    This myFunction is a function on myFile.php but php returns undefined error.
     
    mahmood, Mar 25, 2006 IP
  2. daboss

    daboss Guest

    Messages:
    2,249
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #2
    file 1 needs a function defined in file 2

    in file 1, simply include the following statement and you can start calling the function in file 2

    include("myFile.php");
     
    daboss, Mar 25, 2006 IP
  3. themole

    themole Peon

    Messages:
    82
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    that should work mahmood. could you post the error for us?

    -the mole
     
    themole, Mar 26, 2006 IP
  4. vishwaa

    vishwaa Well-Known Member

    Messages:
    271
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    138
    #4
    verify the path and change the path accordingly.

    like

    include("../../myFile.php");
    or
    include("folder1/myFile.php");
     
    vishwaa, Mar 26, 2006 IP
  5. mahmood

    mahmood Guest

    Messages:
    1,228
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    0
    #5
    This problem occurse only when the include file is placed on the host server and main file is on my computer. What wonders me is that I don't get any error for inclusion but I get "functionName not defined" error.

    If I put say echo "this is test"; on include file, it works fine.
    .
     
    mahmood, Mar 27, 2006 IP
  6. rvarcher

    rvarcher Peon

    Messages:
    69
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Could you copy and paste (specifically copy and paste) the line in your file that calls the function. And the line in the include file that begins the function definition, i.e. function myFunction() {
     
    rvarcher, Mar 27, 2006 IP
  7. themole

    themole Peon

    Messages:
    82
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I think there's some builtin security with PHP and including remote files that I've ran into before. I don't think it will let you call functions. I know I would want someone including a file that connects to localhost and sends user/pass to it.

    I just tried it and calling a function from an external include doesn't work for me. Now that I've thought about it, it's not that it's a deliberate security feature, it's just that apache (or whatever webserver you have) is handling the request, and not php directly opeing the file, when you use include "http://myserver.tld/funcs.php"; try opening your remote (the file your local computer) and see what happens. The functions aren't really there.

    -the mole

    Edited for clarification
     
    themole, Mar 27, 2006 IP
  8. stupidfly

    stupidfly Peon

    Messages:
    129
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I'm having this same problem now. Has anyone found a solution?

    Basically, I want to use some functions in a file on a different domain than the file that is calling the function.
     
    stupidfly, Aug 10, 2007 IP