1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Development php include

Discussion in 'Software' started by Ben, 28 Jan 2005.

  1. Ben

    Ben What's a Dremel?

    Joined:
    11 Aug 2003
    Posts:
    1,000
    Likes Received:
    0
    Say I have got a file that I want to include in php. I gave it the extension .inc

    This works fine when included by a php file. However if some one goes directly to the .inc file they see all the contents not so good, I tried giving the included file .php but that means that it dose not get phrased(?) correctly.
    Is there a way to stop people seeing the contents of these files, was thinking of using .htaccess (did not get to far) or some clever php?

    any ideas.
     
  2. ajack

    ajack rox

    Joined:
    17 Apr 2003
    Posts:
    2,695
    Likes Received:
    2
    Usually the norm is to give it a .inc.php extension; that way it describes it as being an include file, but doesn't show the contents when called up.

    Can you elaborate on this? What do you mean by it doesn't get "phrased correcty"?
     
  3. ellism

    ellism What's a Dremel?

    Joined:
    10 Sep 2003
    Posts:
    348
    Likes Received:
    0
    play with the mime settings on your server to get .inc treated the same as .php.
     
  4. Ben

    Ben What's a Dremel?

    Joined:
    11 Aug 2003
    Posts:
    1,000
    Likes Received:
    0
    Code:
    Fatal error: Call to undefined function: bhtml()
    I get that if the file that I’m including is .php or .inc.php

    Code:
    AddType application/x-httpd-php .html
    If it dose exactly the same as that in .htaccess then it will not work.
     
  5. Ben

    Ben What's a Dremel?

    Joined:
    11 Aug 2003
    Posts:
    1,000
    Likes Received:
    0
    Code:
    AddType application/x-httpd-php .[B]inc[/B]
    :blush:

    that dose not work.
     
  6. Barry

    Barry What's a Dremel?

    Joined:
    23 Jan 2005
    Posts:
    27
    Likes Received:
    0

    Parse error?
     
  7. Ben

    Ben What's a Dremel?

    Joined:
    11 Aug 2003
    Posts:
    1,000
    Likes Received:
    0
    main file
    PHP:
    <?
    @include 
    "http:................/bbcode.inc";
    bhtml(stripslashes($text))
    ?>
    included file

    PHP:
    <?
    function 
    bhtml($text)
    {
    $bbcode = array("<"">",..................td bgcolor=white>", "</td></tr></table>",
                    '"
    >');
    $newtext = str_replace($bbcode, $htmlcode, $text);
    $newtext = nl2br($newtext);
    return $newtext;
    }
    ?>
    if the included file has .inc everything works, if it has .php or .inc.php (im also changing the @include "http:................/bbcode.inc"; bit so it has the right extention )
    i get

    Fatal error: Call to undefined function: bhtml() in /home/michelle/public_html/ben/home/indextest.php on line 71
     
  8. Hamish

    Hamish What's a Dremel?

    Joined:
    25 Nov 2002
    Posts:
    3,649
    Likes Received:
    4
    does it work if you use
    PHP:
    include("bbcode.php");
    ?
     
  9. Ben

    Ben What's a Dremel?

    Joined:
    11 Aug 2003
    Posts:
    1,000
    Likes Received:
    0
    nope same error
     
  10. RTT

    RTT #parp

    Joined:
    12 Mar 2001
    Posts:
    14,120
    Likes Received:
    74
    Looks to me as if you are trying to include a remote file (http:// in your include line). Is the .inc on the remote server being parsed as PHP?

    For that matter, why bother including from a remote file? Just shove the function in the top of the script you need to use it in. :p
     
  11. Ben

    Ben What's a Dremel?

    Joined:
    11 Aug 2003
    Posts:
    1,000
    Likes Received:
    0
    its being used in more than one file & i would like to change one file in future.

    all i want to know is
    1. what to call the file that is being included .inc.php .inc .php. or change .htaccess either of the files.
    2. what to put in the main files show that the included file works and dose not spit out.

    Fatal error: Call to undefined function: bhtml() in /home/michelle/public_html/ben/home/indextest.php on line 71
     
  12. NiHiLiST

    NiHiLiST New-born car whore

    Joined:
    18 Aug 2001
    Posts:
    3,987
    Likes Received:
    6
    RTT is right about it being parsed remotely. When the extension is .inc, the remote server isn't parsing it as PHP and so is sending the PHP code to your script to execute. If you give it a .php extension then it's being parsed on the remote server and as such declares the function on the remote server then outputs nothing to your script.

    You can't really use includes this way to include code from a remote server, otherwise anyone can view that code by going to the right URL.
     
  13. Ben

    Ben What's a Dremel?

    Joined:
    11 Aug 2003
    Posts:
    1,000
    Likes Received:
    0
    Ok so how can I get it to work, or is it simple not possible.

    If its not possible how can I get it so that if it has the extension .inc directly looking at the .inc file by URL will not show the code.
     
  14. Hamish

    Hamish What's a Dremel?

    Joined:
    25 Nov 2002
    Posts:
    3,649
    Likes Received:
    4
    why dont you just put the files on the same server and call it .php?
    and use a relative path rather than http://blahblah/blah.php
     
  15. NiHiLiST

    NiHiLiST New-born car whore

    Joined:
    18 Aug 2001
    Posts:
    3,987
    Likes Received:
    6
    I'd recommend just having it local too, it would save a lot of hassle. You COULD set it so the requesting IP has to be your server.

    PHP:
    <?php

    if ($_SERVER["REMOTE_ADDR"] == "123.45.67.89") {

      echo 
    "<?php";

      
    ?>


    function bhtml($text)
    {
    $bbcode = array("<", ">",..................td bgcolor=white>", "</td></tr></table>",
                    '">');
    $newtext = str_replace($bbcode, $htmlcode, $text);
    $newtext = nl2br($newtext);
    return $newtext;
    }


      <?php

      
    echo "?>";

    } else {

      echo 
    "Please stop trying to look at my code you filthy script kiddies.";

    }

    ?>
    Not a particularly elegant solution but it would work.

    A usable solution would be to have a proxy file of sorts. Your include would be something like
    PHP:
    include("http://domain.com/phpProxy.php?file=myInclude.inc.php");
    Then you have the PHP code you want in "myinclude.inc.php" on the remote server (not displayed as plain text since it's got a .php extension). In "phpProxy.php" you have something along these lines:
    PHP:
    <?php

    if (file_exists($_GET["file"]) && ($_SERVER["REMOTE_ADDR"] == "123.45.67.89")) readfile($_GET["file"]);

    ?>
     
    Last edited: 29 Jan 2005
  16. Ben

    Ben What's a Dremel?

    Joined:
    11 Aug 2003
    Posts:
    1,000
    Likes Received:
    0
    ok made it local and put it in another directory that’s not public but php can use :).
     

Share This Page