Click to See Complete Forum and Search --> : [RESOLVED] Only allowing the PHP code to be visible?


b1u3b0y
04-12-2008, 05:29 PM
Hello

I am currently using the code:

<?php include("file.php"); ?>

to import files that are being used on more then one page or will be replaced fairly often.

I was wondering if there was a way to disable the php code from displaying the html in the file from people who want to view my source code. Whenever view source code is opened everything is displayed from the php file. All I want the user to see is the <?php include("file.php"); ?> code...

Thanks!

felgall
04-12-2008, 06:39 PM
See http://www.felgall.com/php21.htm

b1u3b0y
04-13-2008, 01:24 AM
hmmm so I tried putting the include files into a folder that was only readable write-able and executable by me... but it is still showing all the code in the view source section. Rather then just displaying <?php include("file.php") ?> code only. Maybe I'm doing something wrong...

NogDog
04-13-2008, 09:34 AM
If you mean that you do not want the browser to see the HTML source that is output by your PHP page, that is not possible. The HTML is what actually gets sent to the browser, not the PHP code that generated it.

b1u3b0y
04-13-2008, 12:23 PM
So does that mean that when someone right clicks and then chooses view page source.. There is no way to hide the code that is in the php file?

NogDog
04-13-2008, 12:33 PM
No, there is no way to see the actual PHP code from the browser, assuming that the web server processed the page as PHP and sent the resulting output to the browser. All the that can be seen from the browser is the output from a correctly processed PHP script.

For example, assume this basic PHP file:

<?php
$name = "World";
echo "<p>Hello, $name.</p>";
?>

If you connect to that file with your browser over the internet, you would see:

Hello, World.

If you then did a view source of that page, all you would see is:

<p>Hello, World.</p>

Try it yourself on this site, since it uses PHP. Do a "view source" and all you will see is the HTML output.