PHP not working

Status
Not open for further replies.

folkdisc

New Member
Messages
4
Reaction score
0
Points
1
My site uses html pages with php content. The whole site is dynamic.
For the last few days php is not being processed, which just outputs .htm as nonsense pages.
Also, when I open a page with a .php extension, my browsers open a download popup window, instead of just displaying the page.
For years, I have had few problems. Just occasionally, x10hosting has switched off php encoding, I re-upload a .htaccess file containing this:
‘AddHandler application/x-httpd-php5 .php html .htm .wml .xml .txt’
And everything has worked 100% again… Until now.
What is going on?
 

folkdisc

New Member
Messages
4
Reaction score
0
Points
1
Got it working for both problems using this in .htaccess
Hope this helps somebody.
AddType text/plain .*
AddType application/x-httpd-lsphp .html .htm .php
 

Skizzerz

Contributors
Staff member
Contributors
Messages
2,928
Reaction score
118
Points
63
You do NOT need any custom .htaccess configurations in order to make PHP work on your website. Adding such configurations is very brittle as we change our setup on Free Hosting rather frequently, and such configurations will simply break your website whenever we do changes.

Here is what I recommend doing:
  1. Remove any AddHandler/AddType lines from your .htaccess file
  2. Try loading a .php file, it should work fine
  3. DO NOT put PHP code inside of .htm and .html files -- these are meant to be static files containing only HTML and not PHP code. I make no guarantees that attempting to process PHP code on such file extensions will work in the future as we modify configurations; I know currently we are working on enhanced caching of static files, and if such caching was implemented on a file extension basis, you'd find that your PHP code on those files would only run once and then the cached version of that would be served for every other page load.

For everyone else -- please do not follow folkdisc's advice for exactly the reasons I stated above.
 

folkdisc

New Member
Messages
4
Reaction score
0
Points
1
Using the .htaccess file has been a bit fussy, in that every few months it would get overwritten, and the site would go awol.
Another reply on this forum suggested using mod_rewrite to serve php from html addresses. Would you recommend this?
Or just we-write the site with php extensions?
This would be a bit of a pain.
I guess I have ~5000 pages but all except ~100 are self referencing containers pulling stuff from database.
Most of these are dynamically created.
I could re-write all my html as php generated meta refresh tag pages which wouldn't take too long, and keep both sets live while google catches up?
Suggestions?
 

Skizzerz

Contributors
Staff member
Contributors
Messages
2,928
Reaction score
118
Points
63
I would personally rewrite everything with the .php file extension personally, you can use .htaccess mod_rewrite to make use of "pretty" urls if that was the goal of having .html in the first place (e.g. you could have example.com/pagename actually hit example.com/pagename.php behind-the-scenes). You could also have additional rewrite rules transferring the old .html ones to the new .php ones in a similar vein, and then use a script to do the renames themselves so you don't have to manually rename bunches of files. I wouldn't recommend actually processing PHP from .html files because of the reasons outlined in my post above.

To recap, here are my suggestions. You by no means have to listen to them, but they should help you avoid possibly nasty surprises down the road:
1. Use a script to rename all your .html files to .php -- even if this hits more than it should you'll be safe because straight HTML serves up just fine from a .php file
2. Make use of mod_rewrite to instate some sort of pretty URL scheme, e.g. removing the file extension entirely. This makes your URLs look a lot nicer and may also help improve your rankings in search engines. Note: code below is untested but roughly what you'd want.
Code:
RewriteEngine On
# Don't rewrite existing files/directories
# CONSIDER: additional RewriteConds to prevent access to places you don't want people going, I'd likely include rules guarding against ".." at a minimum
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L]

# Redirect .html to the new extensionless names
RewriteCond %{REQUEST_FILENAME} \.html$
RewriteRule ^(.*)\.html$ http://example.com/$1 [L,R=301]
 

caftpx10

Well-Known Member
Messages
1,534
Reaction score
114
Points
63
I think staff can execute a command in your workspace to make EVERYTHING have an .php extenstion, but if there are a lot of folders then that would be a pain.
This is the command I'm guessing that would be used:
Code:
mv *.html *.php
That is just a guess, which means the command syntax could be wrong (I have never tried that one before in any form) or that there is a better way of doing it. If this command works then I would imagine that this would only affect all files with the .html extension in that directory where it is being executed.
 

bdistler

Well-Known Member
Prime Account
Messages
3,534
Reaction score
196
Points
63
I think staff can execute a command in your workspace to make EVERYTHING have an .php extenstion
Why would staff do it ? - renaming files is a task for the account holder to do
but if there are a lot of folders then that would be a pain
not if you know Bash - which I assume your are making reference to
This is the command I'm guessing that would be used:
Code:
mv *.html *.php
if a staff member tried to use that syntax with Bash - to mass rename files - then they are not as competent - as I think they are
That is just a guess, which means the command syntax could be wrong
it is wrong - if using Bash
what is the point of all your guessing ?

as Skizzerz said above - the user needs to use a script to mass rename files on his account
1. Use a script to rename all your .html files to .php -- even if this hits more than it should you'll be safe because straight HTML serves up just fine from a .php file
 

caftpx10

Well-Known Member
Messages
1,534
Reaction score
114
Points
63
Why would staff do it ? - renaming files is a task for the account holder to do

not if you know Bash - which I assume your are making reference to

if a staff member tried to use that syntax with Bash - to mass rename files - then they are not as competent - as I think they are

it is wrong - if using Bash
what is the point of all your guessing ?

as Skizzerz said above - the user needs to use a script to mass rename files on his account
Remember that is just a guess, it doesn't mean that it's going to happen.
 
Last edited:

folkdisc

New Member
Messages
4
Reaction score
0
Points
1
At a quick guess globally renaming all files .htm->.php would break ~4995 out of ~5000 pages! A few years back, lots of big sites had dynamically served htm pages. I was on a host without mod_rewrite, and it felt like a reasonable decision. But clearly in retrospect...! Thanks for the answers everyone. It'll just be a few hours to fix everything.
 
Status
Not open for further replies.
Top