I've been posting regarding problems to a project I have over the past while. Thanks for all the help. Now, a new one.
What is happening, big picture, is that php queries a MySQL db for some statistics and generates graphics for a web site from those statistics. What I am ending up with is the actual statistical information from the DB in the header of the image. GD_TYPE is set to PNG, so I'll have something like this:
2004-11-17 48.66 4867 2004-11-14 24.12 62 �PNG
followed by other characters that won't paste. Anyway, if I open the png in vi (all this is on Linux FC2) and delete the offending lines, I have an appropriate image. I have dug through the code until my eyes hurt, and can't see where this variable is leaking out. I'll include some sections of code that are most pertinent:
36 $file = file('/home/dshield/public_html/feeds/topports2.txt');
37 foreach ($file as $line) {
38 $temp = explode("\t", trim($line));
39 $bits[] = $temp[1];
40 }
41 foreach ($bits as $port) {
42 //$port=53;
43 if ($port == "" || $port > "65535") { die("Invalid port variable."); }
44 }
Here, the initial file is picked up and the whole process is started.
77 require "$_SERVER[PHP_INC_PATH]/port_report_db.inc";
78
79 // flush();
80
81 if (file_exists("$reportfile") ) {
82 require ("$reportfile");
83 }
Here, the included file points to $reportfile, which contains the statistical data from which the graphics will be generated. Here's a sample of its contents:
2004-11-17 0.24 24
2004-11-14 0 0
The format is date, percentage and count.
85 // First find the maximum value of $p,
86 // and count the rows.
87 $cnt="0";
88 $s = "0";
89 $file = file($reportfile);
90 foreach ($file as $key => $value)
91 {
92 $cnt = $key +1;
93 $explode = explode("\t",trim($value));
94 $percentages[] = $explode[1];
95 if ($percentages > $s) {
96 $s = $percentages;
97 $cnt += 1;
98 }
99 }
Here, we parse $reportfile so that $percentages[] holds the percentage field, and increment $cnt by one.
121 $pcnt = "0";
122 $file = file($reportfile);
123 foreach ($file as $key => $value)
124 {
125 $cnt = $key +1;
126 $explode = explode("\t",trim($value));
127 $percentages = $explode[1];
128 $pcnt += 1;
129 }
130 //$pcnt += 1;
131 if ( $pcnt > $maxpoints ) { break; }
132 $hY = $maxY - ($percentages * $mmaxY);
133 $color = "$green";
134 if ($percentages > $thresh1 ) { $color = "$yellow"; }
135 if ($percentages > $thresh2 ) { $color = "$red"; }
136 // echo ("$d $percentages $hY\n");
137 imagerectangle($im,$x,$maxY,$x+$xs,$hY,$color);
138 // imagefilledrectangle($im,$x,$maxY,$x+2,$hY,$blue);
139 $x += $inc;
140
141
142
143 // imagestring ($im,2,0,0,"$reportfile",$white);
144
145 if (file_exists("$reportfile")) {
146 imagestring ($im,2,0,0,"Couldn't open",$white);
147 imagestring ($im,2,0,10,"$reportfile",$white);
Again, we're looking at the $reportfile. Looking at percentages again and starting to assign color. As a sidenote, when I delete the statistical data from the png, I get the message from lines 146&147.
That's the end of the main processing portion fo the script. When ran, this is wrapped by a perl script that directs the output to the appropriate files. If it is ran without perl, I will have the statistical data, followed by the ascii characters of the png file. The info is actually the entire text of the $reportfile.
If you see it, great. If not, any suggestions of what to check/change?
Thanks,
monger