SMF Support > SMF 2.0.x Support

8: Undefined variable: test

(1/2) > >>

gaz12321:
I was having issues with my forum loading a blank screen occasionally so I contacted my host who told me it was an issue with SMF calling for a function that was banned on their servers, they have solved the issue and now the forum is loading perfect, but I now have thousands of errors appearing in the error log saying '8: Undefined variable: test' on lines 3716, 3719 & 3722 of subs.php.

I have highlighted the 3 lines in the code below, does anyone know what could be causing the issue and how to stop these errors? I have asked my host what they changed to try and help but am waiting for a reply.





// Lookup an IP; try shell_exec first because we can do a timeout on it.
function host_from_ip($ip)
{
   global $modSettings;

   if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
      return $host;
   $t = microtime();

   // If we can't access nslookup/host, PHP 4.1.x might just crash.
   if (@version_compare(PHP_VERSION, '4.2.0') == -1)
      $host = false;

   // Try the Linux host command, perhaps?
   if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
   {
      /*if (!isset($modSettings['host_to_dis']))
         $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
      else
         $test = @shell_exec('host ' . @escapeshellarg($ip));*/

      // Did host say it didn't find anything?
      if (strpos($test, 'not found') !== false)
         $host = '';
      // Invalid server option?
      elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
         updateSettings(array('host_to_dis' => 1));
      // Maybe it found something, after all?
      elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
         $host = $match[1];
   }

   // This is nslookup; usually only Windows, but possibly some Unix?
   if (!isset($host) && strpos(strtolower(PHP_OS), 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
   {
      //$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
      if (strpos($test, 'Non-existent domain') !== false)
         $host = '';
      elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
         $host = $match[1];
   }

   // This is the last try :/.
   if (!isset($host) || $host === false)
      $host = @gethostbyaddr($ip);

   // It took a long time, so let's cache it!
   if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
      cache_put_data('hostlookup-' . $ip, $host, 600);

   return $host;
}





I'm hopeless with this stuff, does anything stand out and if so is there any way to remove the issue from the code without screwing up the forum?

Shambles:
Isn't that $test variable commented out at its declaration?


--- Code: ---/*if (!isset($modSettings['host_to_dis']))
         $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
      else
         $test = @shell_exec('host ' . @escapeshellarg($ip));*/
--- End code ---

gaz12321:
I have asked my host to look into this for me, they said that because there is no issue with how the forum is running they are going to look into disabling this from the error reporting.

Shambles:
In that case you might as well comment out the whole of that function as the errors will continue to get generated.

Maybe disabling host lookups in your admin panel would help.

Arantor:

--- Quote ---Maybe disabling host lookups in your admin panel would help.
--- End quote ---

It would prevent the function being called at all, and would be much safer than commenting the whole function out which would cause it to get very upset.

Navigation

[0] Message Index

[#] Next page

Go to full version