PHP code / version help

I just transferred my website from GoDaddy to Dreamhost.

On GoDaddy, the PHP code worked fine, but now it does not. I’m guessing it’s a version issue.

For example, this code used to return a TRUE on the goDadddy hosted site, but now it never returns TRUE …


…and variables in my forms are not populated as before…but I can get them from this code…

$login = $_POST[‘login’]; //get the login form var

Here is another example…I have this code at the top of some pages to get any passed variables…

while (list($key,$value)=each($HTTP_GET_VARS))
${$key} = $value;

And I get a warning on the each():
Warning: Variable passed to each() is not an array or object

I’m wondering if I need to re-code all my pages, or is there a workaround for this issue?

When I do phpinfo() it says I’m using version 5.2.

Thanks in advance! I’m not a real PHP developer, just trying to get by.

One other thing I noticed…when I pull up a page on my site like this…

…it does not load…but if I fully qualify it…

…it will load. I must be missing some basic settings somewhere. is “fully qualified”, as far as domains go, “fully qualify” doesn’t really apply to URIs. It sounds like you had some mod_rewrite options on your old server that isn’t on the new one. Go see if you had a .htaccess in your webroot on the old server, and compare it to the new one.

Regarding your post variable issues… I remember having some trouble when I moved to dreamhost too, let me see what I can dig up.

It appears goDaddy totally wiped out everything I used to have there when I transferred the domain. Anyway, I did find a .htaccess file in a folder named stats. It only had this line in it…

Options +Indexes

I don’t know anything about the .htaccess file. I did see in another post someone suggested it contain this line…

AddHandler php5-cgi .php .htm .html

Would that allow a user to put in the file name w/o the .php at the end. Also, where should this file reside?

I don’t think that would accomplish what you want.

.htaccess should reside at the highest level of your website, so in dreamhost, it’d be /<domain name/.htaccess

Are you running your own code, or is this an application/script that you downloaded?

Either way, I think you’ll probably need to write some mod_rewrite rules to get the to work properly, maybe something like:

RewriteEngine on
RewriteBase /
RewriteRule ^(.(plus symbol))$ /$1.php [NC]

… but, if someone went to /Page, it would request /Page.php on the backend I think. So if the file was actually named PAGE.php, it’d return a 404, because the case was different.

Also, you should restrict the kinds of characters that you end up passing along, perhaps allowing numbers, alphanumerics, underscores, and dashes would be enough. if so, use:
RewriteRule ^([a-z0-9-_](plus symbol))$ /$1.php [NC]

Edit: Silly me, messed up the 's and the *'s and the .'s. Fixed now. For reference:
. = any single character
(plus) = The previous character 1 or more times

  • = The previous character 0 or more times

We want the rule to only trigger when there’s actually something after the, so we use (plus).

This forum doesn’t like the plus symbol. Substitute (plus symbol) with the actual plus symbol.

I am running my own code that I wrote from scratch. What’s more is that I have another domain hosted by DreamHost that uses the same code in places…and that works fine.

The working site is using PHP Version 4.4.9 and the new site that is NOT working is using PHP Version 5.2.6. I think that’s the issue. Do you know how I can get the older PHP version running on my site? --I know I’ll have to eventually fix the code when the old version is no longer supported…but getting it working now is the important thing.

When I entered these lines into my .htaccess file…

RewriteEngine on
RewriteBase /
RewriteRule ^(.(plus symbol))$ /$1.php [NC]

…and uplodaed it, I get this error…

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

You can compile your own Custom PHP4.


  • Create a cgi-bin folder in your domain directory.

  • Download a Default DreamHost PHP4.4.9

  • Unzip and upload dh-php449.cgi into your cgi-bin directory.

  • Create/add to the domain’s .htaccess:

AddHandler php-cgi .php Action php-cgi /cgi-bin/dh-php449.cgi

  • chmod 644 /.htaccess
  • chmod 711 /cgi-bin
  • chmod 700 /cgi-bin/dh-php449.cgi

Maximum Cash Discount on any plan with MAXCASH

How To Install PHP.INI / ionCube on DreamHost

[quote]RewriteEngine on
RewriteBase /
RewriteRule ^(.(plus symbol))$ /$1.php [NC][/quote]
… and exactly under what conditions do you stop rewriting? Or do you like infinite loops?

:cool: -//-

$HTTP_POST_VARS and the like are deprecated. Please refer to this wiki article for more information.

Max discount on any plan with promocode SCJESSEYTOTAL


Thank you so much! That worked great…except that I had a folder named cgi already and figured out I had to use that one instead of creating a new one named cgi-bin.

Now my depricated code is working again. Thanks to everyone for helping too!

Now I have to start fixing the code for php 5.

I love infinite loops! Rather, I don’t do mod_rewrite too often, didn’t think about that. Something like this maybe?

RewriteRule ^.*.php$ - [L,NC]

… before the other rewriterule statement?

I found the answer on dreamhost’s wiki…

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /$1.php [L,QSA]

Works great! Thanks for everyone chiming in.

DreamHost just moved my account to a new server. And now one of my websites does not work. It is the one that sXi helped me set up PHP4 on.

If I comment out the 2 lines in .HTACCESS, like this…

#AddHandler php-cgi .php
#Action php-cgi /cgi/dh-php449.cgi

…the website works, but all the old PHP4 code does not work, like the $HTTP_GET_VARS.

If I un-comment those lines, I get an internal server error.

Please help!

Here is part of the message from Dreamhost regarding the move…

If a website isn’t working, please make sure you don’t have anything like
"/home/.SOMETHING/username" in any of your sites scripts. Instead, it should
just be “/home/username”. If your site brings up an error with something
between /home/ and /username/, then the path in one of your site files is
incorrect and will need to be updated. If you don’t know how to do this,
please contact us and we’ll be happy to assist you with it.

If you run your own DNS outside of DreamHost (i.e. your domains nameservers
aren’t pointing to us) we can’t make all the necessary changes for you, so
you will need to make these changes yourself. You will have new DNS records
for your domain, mail and MySQL services and can find all of the new records
on the ‘Manage Domains’ section of your panel. Just click the ‘DNS’ link under
your new domain to see your new DNS records that you need to update. You can use
these new values to make the appropriate changes where you’re managing your DNS.

Also, custom PHP (and php.ini) setups will likely be broken by the move. This is
because they would have been built against the old 32bit libraries on the old server
and not the 64bit libraries on this new server. Unfortunately, this isn’t something we
can help you troubleshoot, but you’ll just basically need to rebuild your custom php
(or php.ini) again.

Use a Default DreamHost PHP4.4.9 64 bit version.

Maximum Cash Discount on any plan with MAXCASH

How To Install PHP.INI / ionCube on DreamHost

I downloaded the Default DreamHost PHP4.4.9 64 bit version as you directed, unzipped it, uploaded the cgi file, and modified the .htaccess file accordingly, but it didn’t work…I’m still getting an internal server error.

I tried all kinds of things, checked permissions, etc, but nothing. Any ideas?

BTW – the zip file you pointed me to, when I unzip it, the file inside is php.cgi, which seems like a new naming convention from the last one of dh-php449.cgi. Is the shorter name correct?

right now my htaccess file has these lines…

AddHandler php-cgi .php
Action php-cgi /cgi-big/php.cgi

Thanks for the help!

Check for typos and the file permissions (chmod).

PM me the SFTP login info if you want me to take a quick look.

Maximum Cash Discount on any plan with MAXCASH

How To Install PHP.INI / ionCube on DreamHost

I think I’m going to give up on getting php4 to work. I started looking at my code, and I think I can change it to use php5 syntax.

My main issues are stuff like this…at the top of each file, when I’m posting to the same file or sending URL parms, I have this bit of code…

while (list($key,$value)=each($HTTP_GET_VARS)){
${$key} = $value;

…so suppose the url has a parm like this…

…I used to be able to get the 2009 value from calling this variable…$year. Or if I posted to the same php page, I could get any post variables the same way.

I just have to change each variable to either $_POST[‘variablename’] or $_GET[‘variablename’].

My site isn’t too big, so it’s not that painful.

Thanks for the help. I do really appreciate it!

Updating the code is always the best option :wink:

Maximum Cash Discount on any plan with MAXCASH

How To Install PHP.INI / ionCube on DreamHost

For anyone with the same issue, I deleted my while loop (shown 2 posts above), and as a quick fix, added code like this (for each variable) to the top of the page…


So I get the URL parameter or the posted parameter, and still maintain the var names in the rest of the code. A bit tedious but it works.