HTML comments will still be visible if a user selects view-source
of your page.
If you don't want this, make a dummy PHP statement to enclose your comment within PHP comment tags:
<?php /* Hidden comment */ ?>
NB1. Your page MUST have a .php
extension for this to work!
NB2. Add a file association such that .PHP files automatically open in your preferred browser.
However, this could mess up your local (non-PHP) page if you don't have a PHP interpreter,
Tidy this up as follows:
<?php /* ><!-- Hidden
comment --><boo*/ ?>
The dummy right-chevron after the /*
PHP comment opener completes a bum tag
Then comes the normal HTML comment pair enclosing your comment.
a) The left-chevron of the <boo*/
entry starts another bum HTML tag and;
b) The ?>
closes the PHP comment: its right-chevron also closes the bum HTML tag.
The first character after this left-chevron can be almost anything other than an asterisk or white-space,
1) Add a file association such that .PHP files automatically open in your preferred browser.
2) Enclose the body of your PHP code within HTML comment tags (<!-- -->
)
3) Ensure your PHP code does not rely on your script for your page to display (eg.) a basic version.
This will hide most of your code. However, you must be devious to hide all of it without
upsetting proper execution of PHP server-side.
<?php // ><!-- The // will tell PHP the rest of this line is a comment. /* (Normally we won't want to spread onto more lines, but I need to here so I can comment on what I'm doing: therefore I'm enclosing this within standard PHP comment tags...) The right-chevron that follows // will 'close' the tag as far as HTML is concerned, thus making the <?php directive appear as a bum tag, which will be ignored. Failure to 'close' the tag here will make HTML look for the next right-chevron, which in this case is end of the <style> directive marked in red below. Anything subsequent would probably be displayed. (This procedure will show as an error in view-source: that's inevitable but not harmful. It will *not* cause an error on the PHP page.) This is followed by the standard HTML start comment tag. We're now properly in 'comment mode' in HTML, but out of it in PHP from the next line onwards.*/ echo '<!-' . '-'; /* The line above is necessary because the HTML comment start tag above is 'lost' by PHP, which regards it as a PHP comment, so will not echo it. So make PHP do so now as above. NB. Break up the two hyphens so the non-PHP version can't see they're together. Consecutive hyphens are *not* allowed within HTML comments. Now you can PHP as much as you like... The example below changes the style of the page depending on the value of 'k' input by the user, so hiding the script will just use a previously defined style. */ if (isset ($_GET['k'])) $k = $_GET['k']; else $k = 4; $newcolours = ''; if ($k == 1) $newcolours = 'body { background-color:#e7ef9c; color:#000; } hr { background-color:#000; color:#000; }'; if ($k == 2) $newcolours = 'body { background-color:#fff; color:#000; } hr { background-color:#000; color:#000; }'; if ($k == 3) $newcolours = 'body { background-color:#000; color:#bff; } hr { background-color:#acc; color:#9bb; }'; if ($newcolours !== '') echo '<style type="text/css">' . $newcolours . '</style>'; // Now we've got to the end, we need to close PHP on the line that follows: ?> Now we're outside PHP, but still within an HTML comment, so close it... -->
None of the script and comments will be displayed on either version of the page.
On the PHP page, the source code will be as follows:
<!--Now we're outside PHP, but still within an HTML comment, so close it... -->
On the local page, the source code will be as follows:
<?php // ><!-- The // will tell PHP the rest of this line is a comment. /* (Normally we won't want to...... (PHP code.... ....) ?> Now we're outside PHP, but still within an HTML comment, so close it... -->