I am not at all PHP/Apache fluent and I am having an issue with the only PHP script we have running on an Apache box.

We have a PHP script which as been running fine for a few months.

Suddenly the script stopped working.

This is part of the script:

/* Creación del Archivo */
 $filename="tmp/log$TBK_ID_TRANSACCION.txt";
 $fp=fopen($filename,"w");
 reset($HTTP_POST_VARS);

 fwrite($fp,$graba);			
 fclose($fp);

  if (valmac($filename)==0)
  {
     echo "Mac KO";
	 exit;
  }else{
  	echo "Mac OK";
    exit;
  }


function valmac($filename)
 {
     $cmdline = "cgi-bin/tbk_check_mac.cgi $filename";
	  //echo $cmdline;
	   exec($cmdline,$result,$retint);
	   if ($result[0]=="CORRECTO")
	   {
		 return 1;
	   }	
	   else {
	 	 return 0;
 	  }
 }

I am getting an error which says

Notice: Undefined offset: 0 in /home/mejoresd/public_html/check_param_mac_tmp.php on line 55

Corresponding to the line

if ($result[0]=="CORRECTO")

I dumped the variables:
$cmdline: string(47) "cgi-bin/tbk_check_mac.cgi tmp/log6581439049.txt"
$result: array(0) { }
$retint: int(126)

After some investigation I found out that something (but what ?) as changed on the server and it seems that script, which creates a file can't get access to it. If you look at the image below you'll see that the "owner" changes from 32044 to 99 between 20/12 and 21/12. Strange enough it is since then that we're having this issue.

What does "owner" means as shown in the pic ? Why did it changed from 32044 to 99 corresponding to the date when the system stopped working properly ?

What does "Undefined offset: 0" mean ?

Jean-Luc
www.corobori.com

    Userid #99 is usually the 'nobody' account - the account that usually runs the httpd process.

    Now, as to how to fix this... I'm not sure. I'm no Unix guru, so I can't begin to guess what configuration was changed. All I can say is try setting the [man]umask/man to 0666 before you create/open any files for editing in your PHP script.

    EDIT: Also, using $HTTP_POST_VARS is rather outdated - you might want to change that to $_POST.

      I tried the umask(0666); but it's still the same error.

      What is a "Undefined offset: 0" error ?

        The undefined offset error means you are trying to reference an array element that is not defined (in this case index 0, apparently because the array is empty due to the preceding exec() command not returning any data).

          NogDog wrote:

          The undefined offset error means you are trying to reference an array element that is not defined (in this case index 0, apparently because the array is empty due to the preceding exec() command not returning any data).

          I suppose I'll have to find out why this CGI does not return any data anymore. Used to be working fine :glare:

          It seems that they upgraded PHP. See http://www.mejoresdatos.net/p.php

            Write a Reply...