PHP Calling script Variables not received by Receiving scrip

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
basscomp
Forum Newbie
Posts: 1
Joined: Mon Apr 17, 2006 12:10 pm

PHP Calling script Variables not received by Receiving scrip

Post by basscomp »

feyd | 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]


Hello,

I am somewhat new to PHP. I was handed a script to edit using PHP 3.09 & MySQL. I have Global Variables turned on but somehow, I can't get my receiving script index.php3 to read variables from the calling script alarm.php3.  When I use the GET method in my calling script, I can see all the GET variables in the URL.  Any help will be appreciated.

Regards....

                                
CALLING SCRIPT alarm.php3

Code: Select all

<?php
#ARCHIVE_DIR=$(RELDIR)/src/alarmcenter/alarm.php3
 
require("Cfg.php3");
require("alchk.inc");
include("alarmdb.inc");
 
#Force clients not to cache
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
 
connectAlarmDB();
 
$fc = 1;
 
function setBackground($networks) {
   $color = "green";
   $sth = mysql_query("SELECT DISTINCT level FROM active " .
                "WHERE status NOT IN ('silence','ignore') AND network IN ('" .
                join($networks,"','") . "') ORDER BY level DESC");
   if (mysql_num_rows($sth)) {
      while (list($level) = mysql_fetch_row($sth)) {
         if ($level == "A") { $color = "red"; }
         if ($level == "B") { $color = "yellow"; }
         if ($level == "C") { $color = "yellow"; }
      }
   }
   if ($color == "green") {
      mysql_free_result($sth);
      $sth = mysql_query("SELECT level FROM active " .
                         "WHERE status IN ('silence','ignore') " .
                         "AND network IN ('" . join($networks,"','") . "')");
      if (mysql_num_rows($sth)) {
         $color = "yellow";
      }
   }
   mysql_free_result($sth);
   print('<BODY BACKGROUND="../../browser/bkg-' . $color . '.gif" ' .
      'TEXT="#FFFFFF" LINK="#00FFAA" VLINK="#FFFF44">');
   if ($color == "red") { print('<BGSOUND SRC="../alert.wav">'); } }
 
function showTable($sth) {
?>
   <TABLE BORDER=3 cellspacing=2>
      <TR>
         <TH WIDTH=50>Line</TH>
         <TH WIDTH=50>Hostname</TH>
         <TH>Level</TH>
         <TH WIDTH=50>Start</TH>
         <TH WIDTH=250>Message</TH>
      </TR>
<?php
   while ($row = mysql_fetch_array($sth)) {
      #Get the machine with highest status that has this alarm
      $sth1 = mysql_query("SELECT hostname FROM active " .
         "WHERE linename='" . $row["linename"] . "' " .
         "AND level='" . $row["level"] . "' AND msg='" . $row["msg"] . "'" .
         "ORDER BY network,hostname LIMIT 1");
      $row1 = mysql_fetch_row($sth1);
      $alarmhost = $row1[0];
      mysql_free_result($sth1);
 
?>
 <FORM METHOD=POST ACTION="index.php3"
TARGET="_top">
     <TR>
 
<?php
$colname = array('linename','hostname','level','start','msg','network');
      for ($j=0;$j<sizeof($colname)-1;$j++) {
         print "<TD>" . $row[$colname[$j]] . "</TD>\n";
         if ($colname[$j] == "hostname" && $alarmhost)
            $row[$colname[$j]] = $alarmhost;
         print "<INPUT TYPE=hidden NAME=\"" . $colname[$j] .
               "1\" VALUE=\"" . $row[$colname[$j]] . "\">\n";
         $args .= "&" . $colname[$j] . "=" . $row[$colname[$j]];
      }
      print "<INPUT TYPE=HIDDEN NAME=\"" . $colname[5] .
            "1\" VALUE=\"". $row[$colname[5]] .  "\">";
      if ($row["level"] != 'I') {
         if ($row["status"] == 'silreq') {
            print "<TD>silence pending</TD>";
         } else if ($row["status"] == 'silence') {
            print "<TD>silenced</TD>";
         } else if ($row["status"] == 'ignore') {
            print "<TD>ignored</TD>";
         } else {
?>
         <TD>
            <INPUT TYPE=submit NAME=action VALUE="Silence">
         </TD>
<?php    } ?>
         <TD>
            <INPUT TYPE=submit NAME=action VALUE="Mail">
         </TD>
<?php } ?>
 
<TD><SELECT NAME="expire1">
<OPTION VALUE="1 hr">1 hr
<OPTION VALUE="2 hr">2 hr
<OPTION VALUE="4 hr">4 hr
<OPTION VALUE="6 hr">6 hr
<OPTION VALUE="12 hr">12 hr
<OPTION VALUE="24 hr">24 hr
</SELECT>
</TD>
<TD align=center>
<INPUT TYPE=SUBMIT NAME=action VALUE="Ignore"> </TD>
 
      </TR>
      </FORM>
<?php
  $fc=$fc + 1; }
?>
   </TABLE>
<?php
}
 
function showAlarmTable($net) {
 print "<H3>$net Network</H3>\n";
 #Get the active alarms
 
 $sth = mysql_query("SELECT DISTINCT " .
 "t1.network,t1.linename,t1.hostname,t1.level," .
 "date_format(t1.start,'%H:%i:%s'),t1.msg, status FROM active AS t1, ".
 "ignore_list AS t2 WHERE t1.network='$net' AND t1.level != 'I' " .
 "AND t1.network!=t2.network AND t1.linename!=t2.linename AND " .
 "t1.hostname!=t2.hostname AND t1.msg!=t2.msg ORDER BY " .
 "level, linename");
 
   if (mysql_num_rows($sth)) {
      showTable($sth);
   }
   mysql_free_result($sth);
}
 
function showInfoTable($net) {
   print "<H3>$net Network</H3>\n";
   $sth = mysql_query("SELECT network, linename,hostname,level," .
      "date_format(start,'%H:%i:%s'),msg,status, network  FROM active " .
      "WHERE network='$net' AND level = 'I' ORDER BY linename,rtime");
   if (mysql_num_rows($sth)) {
      showTable($sth);
   }
   mysql_free_result($sth);
}
?>
 
<HTML>
   <HEAD>
      <TITLE>Head-End Alarm Center</TITLE>
      <META HTTP-EQUIV="REFRESH" CONTENT="180; URL=alarm.php3">
   </HEAD>
<?php
# Start of MAIN
 
deleter();//delete expired alarm holds.
#Load config file
$cfg = new Cfg("/usr/browser/config/alarmcenter.cfg");
$networks = explode(" ",$cfg->item("display","networks"));
 
setBackground($networks);
 
print("<H2>Updated @ " . date("H:i:s") . "</H2>\n");
 
print "<H1>Alarms</H1>\n";
array_walk($networks, 'showAlarmTable');
 
print "<H1>Informational</H1>\n";
array_walk($networks, 'showInfoTable');
?>
   </BODY>
</HTML>
RECEIVING SCRIPT index.php3

Code: Select all

<?php
#ARCHIVE_DIR=$(RELDIR)/src/alarmcenter/index.php3
 
require("Cfg.php3");
include("alarmdb.inc");
 
#Identify ourself as a parent frame
$parent="index.php3";
 
function  authenticate()  {
  Header( "WWW-authenticate: basic realm='Head-End Alarm Center'");
  Header( "HTTP/1.0  401  Unauthorized");
  echo  "You  must  enter  a  valid  login  ID  and  password  to  access  the Head-End Alarm Center\n";
  exit;
}
 
#Connect to the database
connectAlarmDB();
 
function ignore_alarm()
{
 
$n = $_POST["network1"];
$l = $_POST["linename1"];
$h = $_POST["hostname1"];
$m = $_POST["msg1"];
$e = $_POST["expire1"];

  
#Assign variables
      switch ($e)
      {
        case "1 hr":
           $e = time() + 3600;
           break;
 
        case "2 hr":
           $e = time() + (2 * 3600);
           break;
 
        case "4 hr":
           $e = time() + (4 * 3600);
           break;
 
        case "6 hr":
           $e = time() + (6 * 3600);
           break;
 
        case "12 hr":
           $e = time() + (12 * 3600);
           break;
 
        case "24 hr":
           $e = time() + (24 * 3600);
           break;
 
        default:
           $e = time() + 3600;
           break;
     }
      $query = "INSERT INTO ignore_list  (unixt_exp, network, " .
      "linename,hostname,msg) VALUES ('$e', '$n', " .
      "'$l','$h', '$m')";
 
      mysql_query($query);
 
 
 }//end ignore
 
 
#Popup an error message.  This probably should be made into a general routine #This must be placed in the <HEAD> section function popup($msg) { ?>
   <SCRIPT LANGUAGE="JavaScript">
   <!-- Begin
   var w = 700;
   var h = 150;
   var winl = (screen.width - w) / 2;
   var wint = (screen.height - h) / 2;
   winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl
   winprops += ',scrollbars=no,toolbar=no'
   win = window.open("", "pop", winprops)
 
   win.document.write('<HTML>');
   win.document.write('<HEAD>');
   win.document.write('<TITLE>Error Message</TITLE>');
   win.document.write('</HEAD>');
   win.document.write('<BODY>');
<?php
   for ($i=0; $i<count($msg); $i++) {
?>
   win.document.write('<?php print $msg[$i] . "<BR>"; ?>'); <?php
   }
?>
   win.document.write('</BODY>');
   win.document.write('</HTML>');
 
   //  End -->
   </SCRIPT>
<?php
}
 
#Silence an alarm - executes alarmsend
function silenceAlarm($linename,$hostname,$level,$start,$msg) {
   global $PHP_AUTH_USER;
 
 
   #Get all the machines that have this alarm
   $sth = mysql_query("SELECT DISTINCT hostname,status,rtime FROM active " .
      "WHERE linename='$linename' AND level='$level' AND msg='$msg'");
 
   $sil = "";
 
   while (list($hostname,$status,$rtime) = mysql_fetch_row($sth)) {
      if ($status == "") {
         $sil .= sprintf("%-8s Y %-8s %-8s %1s %s\n",
                        $PHP_AUTH_USER,$linename,$hostname,$level,$msg);
      } else {
         if ($start == "") {
            $sil .= sprintf("%-8s Y %-8s %-8s %1s %-8s %s\n",
                           $PHP_AUTH_USER,$linename,$hostname,$level,$status,$ms
g);
         } else {
            $sil .= sprintf("%-8s Y %-8s %-8s %1s %-8s %-8s %s\n",
                           $PHP_AUTH_USER,$linename,$hostname,$level,$status,$st
art,$msg);
         }
      }
   }
 
   if ($sil != "") {
      $res = array();
 
      exec("echo '$sil' | /usr/local/bin/sunopw he " .
         "'HECFG=/usr/he/config /usr/he/`cat /usr/he/he.version`/alarmsend -n al armsnd' 2>&1",$res,$rc);
 
      if ($rc != 0) {
         #Display the error message
         for ($i = count($res); $i>0; $i--) {
             $res[$i] = $res[$i-1];
         }
         $res[0] = "<H1>ERROR: Could not send silence</H1>";
         #array_unshift($res,"<H1>ERROR: Could not send silence</H1>");
         popup($res);
         return(-1);
      } else {
         #Let the silence message(s) get processed
         sleep(1);
      }
   }
 
   return(0);
}
 
#Authenticate if necessary
if(!isset($PHP_AUTH_USER) || ($logout && !strcmp($PHP_AUTH_USER,$oldauth))) {
   authenticate();
} else {
   exec("/usr/local/bin/checkpw $PHP_AUTH_USER $PHP_AUTH_PW",$out,$rc);
   if ($rc != 0) {
      authenticate();
   }
}
 
#For close action, redirect to main page to clear POST data if ($action == "Close") {
   header("Location: index.php3");
   exit;
}
 
#Start the HTML
?>
<HTML>
   <HEAD>
      <TITLE>Head-End Alarm Center</TITLE> <?php
 
# Silence - error messages must be output in <HEAD> if ($action == "Silence") {
   if (silenceAlarm($linename,$hostname,$level,$start,$msg) == 0) {
 
      #Send mail for successfully silences level A and B alarms
      if ($level == "A" || $level == "B" ) {
         $action == "Mail";
      }
   }
}
 
if ($action == "Ignore"){
   ignore_alarm();
}
 
?>
   </HEAD>
   <FRAMESET ROWS="70,*">
   <FRAME SRC="title.php3" NAME="title">
      <FRAMESET COLS="170,*">
         <FRAME SRC="network.php3" NAME="network"> <?php
 
# Layout the page according to what action to perform
 
#Composing mail
if ($action == "Mail") {
   $args="parent=$parent&action=$action&linename=$linename&hostname=$hostname" .
      "&level=$level&start=$start&msg=" . urlencode($msg); ?>
         <FRAMESET ROWS="*,300">
            <FRAME SRC="alarm.php3" NAME="alarm">
            <FRAME SRC="mail.php3?<?php print $args ?>" NAME="mail">
         </FRAMESET>
<?php
 
#Default layout
} else {
?>
         <FRAME SRC="alarm.php3" NAME="alarm"> <?php } ?>
      </FRAMESET>
   </FRAMESET>

feyd | 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
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the $_POST superglobal was not introduced until PHP 4.1.0. You need to use $HTTP_POST_VARS.

http://php.net/reserved.variables
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

php3 is pretty ancient, you should seriously considering upgrading to atleast php4+ or even php5+
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Remember when PHP scripts used to look like that. It is like an archeological discovery.
(#10850)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

arborint wrote:Remember when PHP scripts used to look like that. It is like an archeological discovery.
funny thing is thats its not even that long ago!
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Compared to reading cobol it isn't that bad :)
Post Reply