Problem with PHP includes

Discussion in 'PHP' started by adammiller, Nov 28, 2008.

  1. #1
    Hey guys,

    I'm having a problem with a meta include. I want to use the page URL in a switch statement to display meta tags based on the URL using $_SERVER['PHP_SELF'];

    The problem is, the meta.php file is included on all pages using the following example

    <?php include("http://www.mysite.com/includes/meta.php");?>
    Code (markup):
    When $_SERVER['PHP_SELF'] is called in the meta.php file it will show "meta.php" rather than the page thats calling the include. I believe this is because the include command is including the http://www.mysite.com/ rather than being a relative path to the file.

    I have no idea why the include is used this way, but the site developer wont change it to relative paths (its a large site).

    How can I get the URL of the page calling the include? I've tried using $_SERVER ["HTTP_REFERER"], this is empty.


    Any help appreciated.
     
    adammiller, Nov 28, 2008 IP
  2. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #2
    I don't think I had enough coffee or something. Why would you call $_SERVER['PHP_SELF'] within the meta.php file? It should include itself because it is the "page" doing the calling.

    As for your other issue the includes should be relative. Using the full url as you have shown above places an unecessay load on the sever and is just plain laziness on the part of the scriptor.

    Not sure that was 2 cents worth. Maybe I owe you a penny. :)
     
    Colbyt, Nov 28, 2008 IP
  3. iDemonix

    iDemonix Peon

    Messages:
    37
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Not entirely sure but I'd say sod the developer and try it with a relative path
     
    iDemonix, Nov 28, 2008 IP
  4. adammiller

    adammiller Peon

    Messages:
    184
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks guys. I was using PHP_SELF to get the URL and compare it with a list of others to return a specific title, description and keywords tags.

    Problem solved, there's no other way... gotta change it for loads of pages now! Fun!

    Thanks for your replies.
     
    adammiller, Nov 28, 2008 IP
  5. adamhk

    adamhk Member

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #5
    Including file via http will include just result of target php skript.
     
    adamhk, Nov 29, 2008 IP
  6. LaWoure

    LaWoure Guest

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You cant include file that is not your.... because if you include any remote file the server show you just result of PHP code... it would be very easy :)
     
    LaWoure, Nov 29, 2008 IP