Log in

View Full Version : Possible to convert any Html page to PHP



pistolpapa
05-31-2006, 08:38 PM
Is this possible?

Twey
05-31-2006, 09:00 PM
Probably. You mean the file extensions? Yes.

djr33
06-01-2006, 12:07 AM
php and html are completely the same, EXCEPT for one thing:

Anything between <?php and ?> tags is parsed (as php) and then outputted as html.
Example:
IF ANY OF THE FOLLOWING LINES WERE "test.php":
<?php echo "<html><body>test</body></html>"; ?>
<html><?php echo "<body>test</body>"; ?></html>
<html><body>test</body></html>
You would see the same exact output.

And, yeah, like Twey says, you can just rename the file extension.

the only catch to that is that *I think* (in most cases at least) your server must be php enabled (installed/turned on) for even a pure html page with extension .php to work. If not, it's treated like a .txt... shows the code.
(random note... .phps extension shows the source code, if you want that instead.... should show html source too, I suppose.)

Twey
06-01-2006, 01:08 AM
If not, it's treated like a .txt... shows the code.Depends how the browser's configured. Most will attempt to download the file.

pistolpapa
06-01-2006, 01:33 AM
Sorry, I wasn't clear enough. I acutually meant to convert the client side page to a server side page, so people who visit your website can't possible steal your code.

Twey
06-01-2006, 01:43 AM
I don't think you quite understand the model :)
Server-side scripts send all the client-side code to the client anyway. It's only the purely server-side code, such as database operations, that doesn't get output. The output of that code, however, does.
For example, if you have:
<?php for($i = 0; $i < 4; $i ++)
echo("<p>$i</p>\n"); ?>... the client will see:
<p>0</p>
<p>1</p>
<p>2</p>
<p>3</p>

djr33
06-01-2006, 03:03 AM
Most will attempt to download the file.
Haven't played with it too much... safari decides its text. Or was it mozilla. Whatever.
It won't display as html either way.




If you are talking about converting client side scripting, such as javascript, it's possible... but the syntax varies, so you'd have to go through command by command and be sure all of the operations-- especially the functions-- are supported by php.
the languages are similar in general structure/method, though, so the framework of the script could still get you there... just would need some reworking.

As for hiding your source, no, nope, not gonna happen.
Except the php code itself... output will be seen.

now... using php instead of javascript (where they can be switched... nothing that changes without refreshing, at least) would hide your scripts' source... but only for scripts.
that might be useful.
Like.. a script that gets the current time.
then again... not like that is so secret :p
But... yeah... it will hide php code.