Forum Moderators: coopster
Not sure what I did, but a major error has occurred on my website. I should preface my question with the fact that I am a newby to php so be gentle.
What I have tried to do on my website is have a php include file that strips out the file name and uses it as the title for wherever I need it on the page. It was working fine, up until a couple days ago. I'm not sure if it is something I did, or something going on with Godaddy, where I host my site. But for the last couple days it has been populating "X-httpd-php5" instead of printing the file name.
Listed below is the code for the include file. I copied it verbatim from the book PHP Solutions.
<?php
//this part remains the same
$title = basename($_SERVER['SCRIPT_NAME'], '.php');
$title = str_replace('_', ' ', $title);
//below are changes
$title = strtolower($title);
$titleArr = explode(" ", $title); //creating an array of words from $title
$strToCaps= array("mbt", "php", "html"); //words to strtoupper()
//running strtoupper() with all words found in $strToCaps and ucwords() for all others
foreach(array_keys($titleArr) as $key){
if(in_array($titleArr[$key], $strToCaps)){
$titleArr[$key] = strtoupper($titleArr[$key]);
}
else{
$titleArr[$key] = ucwords($titleArr[$key]);
}
}
//reforming the string
$newTitle = implode(" ", $titleArr);
?>
Another thing I should not is that I am using extensionless urls. Meaning I have the .php taken off. I did this in my .htaccess file.
I don't think it has anything to do with the code not working, because it did work before. But maybe I'm wrong.
This is a copy of my .htaccess file:
DefaultType application/x-httpd-php
AddHandler x-httpd-php5 .php
AddHandler x-httpd-php .php4
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php?\ HTTP/ [NC]
RewriteRule ^(.*)index.php?$ http://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]
I really appreciate any help I can get on this.
Thanks,
Michael
[edited by: dreamcatcher at 9:10 pm (utc) on Mar. 17, 2008]
[edit reason] Use example.com, thanks. [/edit]
Man this is frustrating. One minute it works, the next day it reverts back. I'm wondering if someone is hacking in to my site?
Anyway, I've tried replacing the echo with the print_r command as suggested and it still doesn't work. I'm thinking it must be something wrong with my htaccess file, but I'm not sure.
Any further help is appreciated.
Michael
Anyway, I've tried replacing the echo with the print_r command as suggested and it still doesn't work.
The suggestion to use print_r() is just to try and debug your script, it is not a solution per se. print_r() outputs (ie. dumps) the contents of the variable you pass to it. $_SERVER is an associative array (and a superglobal - available to all your script) from which you are getting the 'SCRIPT_NAME'. It contains many other things, IP address, server name etc...
I suppose the fundamental question is, what does $_SERVER['SCRIPT_NAME'] contain?
What was the result of the $_SERVER array?
It was working fine, up until a couple days ago.
Includes on my .html pages always worked fine on my main hosting with what I had in .htaccess - until a few days ago, when pages started to "download" when accessed. I tried everything imaginable and got that to stop but could not get the includes to work, the navigation just stayed blank. I submitted a support ticket, suspecting a server config change.
It turns out they had updated Apache, and the handlers were disabled by default with the new update. They then enabled it on their end, and my includes started working again immediately. This is still PHP4, but they also support PHP5. If I want to use PHP5 now, I either have to add it to .htaccess or will have to use the .php5 file extension on pages.
That said, since I've also had this happen a few times before, once at another host a few months ago when they updated, and also ran into a similar issue with a new host a while back, where the configuration was different, I suspect it may not be something you did or can control.
Dealing with shared hosting is different from being in control of the server. It appears that when all of a sudden something doesn't work, there's been an update or change on their end, and things are different that aren't in our control with .htaccess
I don't know very much - just enough to know that I need to ask, but based on my experience with the issue 3 times recently, my thought in your case is that they might have updated something (it happens with hosts all the time) and the configuration is changed - and using php might not now be enabled for pages not using file extensions, as you're doing.
What happens if you test a page using .php or .php5 extension? can you do that?
Make sure there wasn't something you changed just before all this started happening...and if there was... try to change it back... I always archive my site files before working on them from one session to the next... saved my butt more than once...
Also... again... maybe it was a server change you were unaware of as she mentioned... that has happend to me as well.
Russ
<?php
echo phpinfo();
?>
It gives a wealth of information, and in particular look at the date of the current Apache build in use. (And second - the PHP version.) The build date was where I got the first clue the first time I had a host change something that caused a problem with PHP includes - it was evident by seeing that date.
Then delete that php_info file for security reasons.
Even with a change, it may be possible to fix the problem on your own by a little testing. If there's a problem on your end (given that you didn't make changes to the script you're using), this is probably where the problem is or changes would need to be made:
DefaultType application/x-httpd-php
AddHandler x-httpd-php5 .php
AddHandler x-httpd-php .php4
Is it PHP4 or PHP5 being run? And what happens if you add a line like this?
AddHandler x-httpd-php5 (without .php as you have it now)
and/or this?
AddHandler x-httpd-php (without .php4 as you have it now and in addition to DefaultType)
In addition to keeping a backup of the current file, make sure to comment out anything being replaced, with a notation, and add comments to whatever you put in to test, so it'll be easy to back out of whatever changes you try.
I copied it verbatim from the book PHP Solutions.
Even without being able yet to write code (yet), it can be a tremendous help for trouble-shooting to learn to read code, and the best learning lab for that is to keep the syntax in the book next to the computer for reference and read through threads in this forum, which is like a real-life learning lab, with practical problems and issues and practical working answers and solutions given.
I ran the info file as suggested and this is the info:
PHP Version 5.2.5
Build Date Mar 3 2008 12:59:56
So this does jive with when the problem started, which was at the beginning of this month.
I have always known that I have php5 and actually upgraded to that so that I could use xml with Amazon for my site.
I used the addhandlers per Godaddy to configure it so that even though I use php5, I don't have to name my files with that extension.
I'll post more after I talk with them...I'm on hold.
Thanks,
Michael
p.s., I reuploaded a backup copy of .htaccess and after 10 minutes in went back to normal. But then I checked it again this morning and the errors are there again. Very strange.