Screwy Hosting Settings....

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

Ok, some of you may have seen my post about "you get what you pay for" in the section on hosting here, and know that our company has set up an account on a "cheap" host that becuase of their default setting of PHP scripts running as our own username, allowed a script that someone tried out to modify our web pages.

Well the two of us who program are "stuck" with that server... And have found another weird thing... Trying to use a form and getting the values via $_POST array...

They are not there. And they are not in the old $HTTP_POST_VARS and they are also not just autmatically made into variables..... doing a print_r($GLOBALS) shows that the ONLY place the post data is located is in a variable (NOT ARRAY) called $HTTP_RAW_POST_DATA.

For example, if you have this form:

    Name: [Greg           ]
Address: [123 Main St.   ]
    City: [Anytown        ]
   State: [OH     [v]] (dropdown list)
     Zip: [44325]
   Phone: [330-555-1212]
Comments: [I would like to lean PHP ] (these 3 lines
          [Please train me.         ]  are a textarea
          [I can pay a lot of $$    ]  form field)
HeadFrom: [my brother     ]
'here is the ONLY value you get in PHP, assigned to $HTTP_RAW_POST_DATA:
Name=Greg
Address=123 Main St.
City=Anytown
State=OH
Zip=44325
Phone=330-555-1212
Comments=I would like to lean PHP
Please train me.
I can pay a lot of $$
HeadFrom=my brother
'Well I do have a "hack" for it, however if someone enters an "=" in a multiline textarea after the first line, it will casue it to glitch. Here is what I am using:
<?php
$ar1
= split(\"\n\",$HTTP_RAW_POST_DATA);
foreach (
$ar1 as $val)
{
  
$pos = strpos($val,\"=\");
   if (
$pos >0)
   {
      list(
$key,$data) = split(\"=\",$val);
     
$_POST[$key] = trim($data);
   }
   else
     
$_POST[$key] .= \"\n\" . trim($val);
}
?>
Has anyone ever seen a server set up like this?? they are running PHP 5.0.3 i think it was (definately version 5) Any attempts to put PHP settings in .htaccess casue server errors, I was willing to go back to the old way by setting the php_flag register_globals value, but it wouldn't work on or off.... Mad

Again, you get what you pay for.....

-Greg

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

You are most likely getting errors from setting values in your .htaccess file because your host has PHP compiled as a CGI module and not an Apache module. You may be able to change the PHP settings by having a local php.ini file depending if your host has it enabled.

I don't see anywhere in my php.ini file where I can enable/disable the $_POST variable. By looking at this page, it looks like it could be a bug with your version. Here is a possible workaround for that bug if that's what it is:

<?php
if (isset($GLOBALS['HTTP_RAW_POST_DATA']) && !count($_POST))
 
parse_str($GLOBALS['HTTP_RAW_POST_DATA']  , $_POST);
?>

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

Not sure if that is the issue... even if that is the problem amazing that a hosting company wouldn't have info on their site about it....

The fix you gave depends on a string being like a query string var1=data1&var2data2&var3=data3 however that is not the case I have. It takes each item and places it on a newline...

Very strange....

-Greg

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

If the new line is a problem, run something like this.

<?php
if (isset($GLOBALS['HTTP_RAW_POST_DATA']) && !count($_POST))
{
   
$data = str_replace(\"\n\", '&', $GLOBALS['HTTP_RAW_POST_DATA']);
    parse_str(
$data  , $_POST);
}
?>

Whether it's a bug or not, that should work as a workaround.

Quote: Not sure if that is the issue... even if that is the problem amazing that a hosting company wouldn't have info on their site about it....

"You get what you pay for." Sticking out tongue

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

I still need to stick with what I got as the possibility of text areas including new lines as well. (see my example filled out form and how the server gives it to me)

-Greg

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

I contacted the hosting comapny regarding this. Here is their reply:

Quote: This will be scripting issue and we don't provide support fot scripting issues.

Yet on their website they list PHP as one of the features they offer and that they offer "24x7x365 Live Support by the [name removed] team of experienced professionals."

And i still have not gotten a reply back from another e-mail sent 2 days ago....

I tell you i'm half tempted to post the hosting company's name here, but since it is work related, I shouldn't.

-Greg

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.