Forum Moderators: coopster

Message Too Old, No Replies

X-httpd-php5 error

         

mkingsle

8:52 pm on Mar 17, 2008 (gmt 0)

10+ Year Member



Hey everyone:

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]

coopster

9:41 pm on Mar 18, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I don't understand how you are getting the "x-httpd-php5" in your title but I would start first by dumping the $_SERVER array before you use it to see what, if anything, has changed on you.

mkingsle

4:00 pm on Mar 26, 2008 (gmt 0)

10+ Year Member



I guess I'm not sure what you mean? What do you mean to dump it. how would I alter the code.

Thanks

PHP_Chimp

5:06 pm on Mar 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am assuming coopster means bump it as in bump it to screen

echo '<pre>';
print_r($_SERVER);
echo '</pre>';

So you can see if there is any change to the server array.

mkingsle

5:45 pm on Mar 26, 2008 (gmt 0)

10+ Year Member



I have no clue what you guys mean. Sorry, I'm an idiot at this sometimes.

PHP_Chimp

9:23 pm on Mar 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think I'm showing my dyslexia
bump it as in bump it to screen

Should of course have been dump.

dump (or for the spellingly challenged bump ;) = echo. As $_SERVER is an array you need to use print_r to get a better echo.

mkingsle

1:32 pm on Mar 28, 2008 (gmt 0)

10+ Year Member



Hey again:

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

penders

2:05 pm on Mar 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



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?

PHP_Chimp

11:34 am on Mar 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As you said that sometimes this problem is there and other times it is not I would also suggest changing any redirects that you have in your htaccess to 302's (change them back once the problem is sorted). As otherwise you may well be getting a cached copy of a location from the browser, as it will remember that it should be 301'ing a request.

What was the result of the $_SERVER array?

Marcia

12:13 pm on Mar 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It was working fine, up until a couple days ago.

That could possibly be it right there. Things don't just stop working "all of a sudden" without a reason.

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?

russkern

7:21 pm on Mar 29, 2008 (gmt 0)

10+ Year Member



I can;t be of much help on this particular issue, but I would firmly agree with a few things that Marcia said... The main one being... "things don't just stop working for no reason"

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

Marcia

3:46 am on Mar 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Upload a file called php_info.php into the root of your site. This is all it needs to contain:

<?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.

That's the pitfall of using copy and paste code, which may be totally workable but won't be a help with server dependent specifics. I have the same book, and Powell's coverage of the PHP syntax is excellent: very clear and easy to read and use.

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.

mkingsle

2:59 pm on Mar 31, 2008 (gmt 0)

10+ Year Member



Thanks everyone for the replies. I am talking with Godaddy as I type to see if it is something on their end.

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.

mkingsle

6:57 pm on Mar 31, 2008 (gmt 0)

10+ Year Member



Well, Godaddy wasn't any help.

They put in a ticket for there specialists to take a look.

So I'm back to square one.

Boy is this frustrating.

mkingsle

7:05 pm on Mar 31, 2008 (gmt 0)

10+ Year Member



Well, I played with it again and took out this line:

AddHandler x-httpd-php5 .php

and everything went back to normal.

Question is why? I was under the impression that I need this in order to have php 5 work when I don't use the .php5 extension and just use .php

Any suggestions?

Thanks.