Simple Question: why wont this php class link properly?

Discussion in 'PHP' started by gadgetpro, Jun 6, 2009.

  1. #1
    I created a php class and it works fine with the php require for one of my pages that uses the class only when i have the shop.php in the same directory as the page:

    require("shop.php") 
    Code (markup):
    but the problem is that I want to link to the shop class so multiple pages have direct access to it so i can update the file easily instead of putting the file in five different directories, but when I do the page does not work and I get an error.

    require("http://www.mysite.com/shop.php"); 
    Code (markup):
    Why wont the php class work when I just give the page a path to it instead of having it in the same directory??
     
    gadgetpro, Jun 6, 2009 IP
  2. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #2
    require requires absolute path, so you need to do something like:

    require('/user/home/dir/shop.php');

    Contact your host for the absolute path to your home directory.

    Peace,
     
    Barti1987, Jun 6, 2009 IP
  3. Louis11

    Louis11 Active Member

    Messages:
    783
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    70
    #3
    In most instances you cannot include/require files across domains. This is typically restricted (in php.ini) as a security measure.

    What you need to do is include the file relative to its location. Similar to what you have, minus the URL. So . . .

    
    require('includes/included_file.php');
    
    Code (markup):
    Would include 'included_file.php' in the includes directory in the current working directory.

    
    require('../../includes/included_file.php');
    
    Code (markup):
    Would be an included file (included_file.php) up two directories in the 'includes' directory.
     
    Louis11, Jun 6, 2009 IP
  4. stompergames

    stompergames Peon

    Messages:
    222
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thanks a ton guys (same user here)!!!!
     
    stompergames, Jun 7, 2009 IP