Question about file extensions
Moderator: General Moderators
Question about file extensions
I am new to PHP and am not having as many questions about the syntax/code as I am about overall implementation. I'm hoping somebody can give me some insight into this question:
I assume you need a .php extension on your page to run php code in the page. So if you want to use sessions and session variables, it would seem every page in your site would need to be .php (and not .html). On each page of the site, I want to echo that the user is logged in (something like "Logged in as user"). I feel like I see sites that can do that as an .html page, but maybe I'm wrong.
I don't mind making every page a .php page, but was just curious if there's a better way I should be managing it. Thanks for your help.
Ryan
I assume you need a .php extension on your page to run php code in the page. So if you want to use sessions and session variables, it would seem every page in your site would need to be .php (and not .html). On each page of the site, I want to echo that the user is logged in (something like "Logged in as user"). I feel like I see sites that can do that as an .html page, but maybe I'm wrong.
I don't mind making every page a .php page, but was just curious if there's a better way I should be managing it. Thanks for your help.
Ryan
Re: Question about file extensions
No, you are not wrong. It is possible, you need to tell your server to treat .html files just like if they were .php files.RyanP wrote:I feel like I see sites that can do that as an .html page, but maybe I'm wrong.
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
File extensions mean nothing. They are only used for quick identification of file types. You can rename a file and it'll still have the exact same data. If you made your image editing software recognize *.blah files as JPEGs, it'd load the data the same way. The same goes for your server. php.exe is a program and needs to know which files to be run on.
You could also do a server-side include
in html to include a php header on a static html page... assuming your apache has includes enabled.
Code: Select all
<!--#include virtual="/header.php" -->Thanks for the help. And that raises an additional question I have...I know I have control over my php.ini file and my local apache environment, but when I host the site with a service provider, who determines the php settings then? Will I have a control panel to modify those myself, or will the service provider dictate that stuff? (For example, would there be a way to have my hoster allow me to run html files as php?) Thanks!
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Most hosts will probably not allow HTML files to be interpreted as PHP because it could have an effect on the entire server. It is not that huge of an issue for a single site to have every requested html file sent through the PHP engine. But when there are 50 on a box, it could have some serious implications.
There is a possibility that you could use some rewrite rules in a .htaccess file to push any extension file into a .php file and your users would be none the wiser.
There is a possibility that you could use some rewrite rules in a .htaccess file to push any extension file into a .php file and your users would be none the wiser.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Put this in your .htaccess file and save it at the root of your site. That should make it so .html files will be read as php.I assume you need a .php extension on your page to run php code in the page. So if you want to use sessions and session variables, it would seem every page in your site would need to be .php (and not .html).
Code: Select all
AddType application/x-httpd-php .htmlThe only problem I find in doing this, some IDE's parse and display code according to its extension.