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.
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"?
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.
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
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.
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
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.
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.
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
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"]); ?>