Strange problem after server upgrade - no error message.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rickot1
Forum Newbie
Posts: 2
Joined: Thu Nov 30, 2006 10:41 am

Strange problem after server upgrade - no error message.

Post by rickot1 »

Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I developed a site several years ago that has never had any problems.

However, this week our hosting company upgraded servers and now whenever I try navigate or pull data on the site using any kind of form function I get nothing. 

You can see an example at http://www.tcvb.org/dining.php . The dropdown is pulling from the database so it doesn't seem to be database related. I also tried this site on another new server and have the same problem. 

I'm a beginner PHP developer and this code was done by a former developer. I would probably not do this the way he did but I don't really want to rewrite anything I don't have to. Any suggestions anyone might be able to provide might be a lifesaver. 

Here is the PHP code for this page (minus database connection info)

Code: Select all

<?php
	//switch ($process) {
		//default:
			$connection=mysql_connect ("", "", "") or die (mysql_error());
			$db=mysql_select_db ("", $connection) or die (mysql_error());
			$query = "SELECT DISTINCT rType FROM dining";
			$sql_result = mysql_query($query, $connection) or die (mysql_error());
			
			echo"
				<table border=0 cellpadding=0 cellspacing=0 align=left>
					<tr>
						<td>
							<form method='POST' action='$PHP_SELF?process=view'>
				    		  <select name='type' onChange='this.form.submit()'>
								<option value=''> -- Dining Types -- </option>";
								
									while ($row = mysql_fetch_array($sql_result)) {
										$rType = $row["rType"];
		 								echo "<option value = '$rType'>$rType</option>";
									}
									
			                        echo "	
				             </select>
						</td>
					</tr>
				</table>
				<br><br><br>
			";
		//break;
	
	switch ($process) {
		case "view":
			$type = $_REQUEST["type"];
			
			$connection=mysql_connect ("localhost", "", "") or die (mysql_error());
			$db=mysql_select_db ("", $connection) or die (mysql_error());
			$query = "SELECT * FROM dining WHERE rType = '$type' ORDER BY rName ASC";
			$sql_result = mysql_query($query, $connection) or die (mysql_error());
			
			echo"
				<table border=0 cellpadding=0 cellspacing=0 align=left>
				<tr>
					<td>
						<table cellspacing='1' cellpadding='0' border='0' bgcolor='#FFFFFF' align='center'>
							<tr>
								<td style='font-family:verdana; color:black; font-weight:bold; font-size:13px; text-transform:uppercase; text-decoration:underline;'>
									".$_POST["type"]."
								</td>
							</tr>
							<tr><td>&nbsp;</td></tr>
						";
						while ($row = mysql_fetch_array($sql_result)) {	
								$id= $row["id"];
								$rName = $row["rName"];
								$rAddress = $row["rAddress"];
								$rLocal = $row["rLocal"];
								$rFax = $row["rFax"];
								$rTollfree = $row["rTollfree"];
								$rWeb = $row["rWeb"];
								$rInfo = $row["rInfo"];
								$rType = $row["rType"];
								
									$rName = str_replace('\"','"',$rName);
									$rName = str_replace("\'","'",$rName);
									$rInfo = str_replace('\"','"',$rInfo);
									$rInfo = str_replace("\'","'",$rInfo);
									$rInfo = str_replace(":::","<br>", $rInfo);
									$rInfo = str_replace("::","<p>", $rInfo);
									
							echo"
									<tr bgcolor='#ffffff'>
										<td valign=top class='bodytx'> 
											<span style='font-size:11px; color:maroon; font-weight:bold;'><b>$rName</b></span><br>
											$rAddress<br>
											<i>Local:</i> $rLocal<br>
											";
												if ($rFax) { echo"<i>Fax:</i> $rFax<br>"; } else { echo""; }
												if ($rTollfree) { echo"<i>Toll Free:</i> $rTollfree<br>"; } else { echo""; }
												if ($rWeb) { echo"<a href='http://".$rWeb."' target=_blank>$rWeb</a><br>"; } else { echo""; }
											echo"
											<i>$rInfo</i>
										</td>
									</tr>
									<tr><td>&nbsp;</td></tr>";
							
							}
			echo"
							</table>
						</td>
					</tr>
				</table>
			";
		break;
	}
?>

Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

If form functions aren't working now, but they did before, I would bet it has to do with register_globals being turned off in the new setup. This is better for you (from a Security standpoint) but a pain in the neck when you have to go through your entire site and actually declare each var that you use to pull as a global as its appropriate global array var ($_GET, $_POST, $_COOKIE, $_SESSION).

Just to be sure, run the following in a new file and tell us the results please.

Code: Select all

<?php

$neg = array('off', 0, false, '', null);
$flags = array(
	'Register Globals' => 'register_globals',
	'Short Tags' => 'short_open_tag',
	'Display Errors' => 'display_errors',
	'Magic Quotes GPC' => 'magic_quotes_gpc',
	'Magic Quotes Runtime' => 'magic_quotes_runtime',
	'Magic Quotes Sybase' => 'magic_quotes_sybase',
);
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
foreach ($flags as $n => $v)
{
	$flags[$n] = (in_array(strtolower(ini_get($v)), $neg) ? 'Off' : 'On');
}
$cli = (php_sapi_name() == 'cli');
$eol = "\n";

$gle = get_loaded_extensions();
$rows = array();
$le = '';
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
	$le .= '   ' . implode('   ', array_slice($gle, $i, $wide)) . $eol;
}

$ec = array(
	'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
	'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
	'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
	'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);

$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
	if (($t & $v) == $v)
	{
		$e[] = $n;
		$t ^= $v;
	}
}
if (ceil(count($ec) / 2) + 1 < count($e))
{
	$e2 = array();
	foreach ($ec as $n => $v)
	{
		if (!in_array($n, $e) and $n != 'E_ALL')
		{
			$e2[] = $n;
		}
	}
	$er = $er . ' ((E_ALL | E_STRICT) ^ ' . implode(' ^ ', $e2) . '))';
}
else
{
	$er = $er . ' (' . implode(' | ', $e) . ')';
}

if (!$cli)
{
	echo '<html><head><title>quick info</title></head><body><pre>', $eol;
}

echo 'PHP Version: ', $ve, $eol;
echo 'PHP OS: ', $os, $eol;
echo 'Error Reporting: ', $er, $eol;
foreach ($flags as $n => $v)
{
	echo $n, ': ', $v, $eol;
}
echo 'Loaded Extensions:', $eol, $le, $eol;

if (!$cli)
{
	echo '</pre></body></html>', $eol;
}

?>
rickot1
Forum Newbie
Posts: 2
Joined: Thu Nov 30, 2006 10:41 am

Post by rickot1 »

You're my new friend. That was it.

Host suggested putting a php.ini file in the directory and it solved with the line register_globals = On .

That seems to have solved it. There's really no need for real tight security on this site because there is no sensitive information and the database is backed up regularly. But is it something I should worry enough about to try and declare each var?

We're going to be launching a completely new site in the next couple of months so I don't really care to put forth the effort if it's not important.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Register Globals should be your sworn mortal enemy. Even if you are not really concerned with your database, you should be concerned with the security of your server (and the security of the others being hosted on the same box as you). I would get in the groove of working as thought register globals is off as soon as possible.
Post Reply