php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35365 phpinfo's css affects other parts of page
Submitted: 2005-11-24 13:09 UTC Modified: 2005-11-24 13:38 UTC
Votes:4
Avg. Score:4.2 ± 0.8
Reproduced:3 of 4 (75.0%)
Same Version:2 (66.7%)
Same OS:2 (66.7%)
From: csaba at alum dot mit dot edu Assigned:
Status: Wont fix Package: PHP options/info functions
PHP Version: 5CVS-2005-11-24 (snap) OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: csaba at alum dot mit dot edu
New email:
PHP Version: OS:

 

 [2005-11-24 13:09 UTC] csaba at alum dot mit dot edu
Description:
------------
phpinfo's style sheet drastically affects other parts of the web page being generated, and there seems to be no compelling reason for it.

For example, note the output of the following .php page:
<html><head><title>phpinfo test page</title></head>
<body bgcolor=yellow>
<table border>
<tr><td>Row1, Col1</td>
    <td>Row1, Col2</td></tr>
<tr><td>Row2, Col1</td>
    <td>Row2, Col2 <img
src='http://us.geo1.yimg.com/pic.geocities.com/img/filemgr/folder.gif'
alt='img alt' title='img title'></td></tr>
</table>
</body>
</html>

In particular, on both IE 6 and FF,
there are thick light borders, yellow background,
serif fonts, and row 2, cell 2 has only one line


Now add the following line:
<?php phpinfo(); ?>

While this prints out the php information, it drastically alters the appearance of the table at the top of the page.  Specifically, the background color has gone from yellow to white, the table borders are now all thin, dark lines, the fonts are now all sans serif, and row 2, cell 2 now has 2 lines with the text on the top line and the image to the right on the line below.

Expected result:
----------------
I expect the original page, by and large, to remain the same as before phpinfo was invoked.  In particular, the bulk of the problems happen because many of phpinfo()'s style declarations are applied to element types instead of phpinfo() specific classes within an element type.  For example,
table { ... } affects all tables and not just phpinfo()'s tables.  I would like to suggest making a phpinfo() specific class and using this for all elements generated with phpinfo()

Thanks,
Csaba Gabor from Vienna


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-24 13:17 UTC] derick@php.net
This is a debug tool....
 [2005-11-24 13:27 UTC] csaba at alum dot mit dot edu
This is the second half of the report.  It is a poor man's "band aid" code to show that phpinfo() could produce output that doesn't interfere with the prior parts of the page.  I say "poor man's" because this type of preg_replacing is not bulletproof, and the fix really belongs in the bowels of php and not as an external revision.  The short classes like .v should be eliminated and really there should only be a .phpinfo class and maybe one or two others (to differentiate between td.v and td.e for example) - but this is secondary.  I'm no expert in CSS, though.

To see it work, replace <?php phpinfo(); ?> in the original report with the code below (all of which should be below the example page (the demo table) found at the top of this bug report.

... base page goes here ...
<?php 
$phpinfo = phpinfoRevised();
print $phpinfo;

function phpinfoRevised() {
  ob_start();
  phpinfo();
  $phpinfo = ob_get_contents();
  ob_end_clean();

  $aClasses = array("body", "h1", "h2", "pre", "img", "center", "hr");	// to redeclare
  $cP = "phpinfo";			// $cP = classPrefix

  // All phpinfo() tables are within .center
  // so we move table {...} to .center table {...}
  xferCSS("table", ".center table", $phpinfo);
  // changes to body would affect all body elements
  xferCSS("body", ".center", $phpinfo);

  $phpinfo = preg_replace("/td, th (.*)\\}/",
     "td.e, td.v, .{$cP}td, .{$cP}th $1}",$phpinfo);
  $phpinfo = preg_replace("/^body, td(.*)\\{(.*)\\}/m",
     "td.e, td.v, .{$cP}td, .{$cP}th, .{$cP}h1, " .
     ".{$cP}h2 {\$2}", $phpinfo);
  redeclareClass ($aClasses, $phpinfo, $cP);

  // else images float right:
  reclass ($phpinfo, "img", $cP . "img", false, " ");
  reclass($phpinfo, "td", $cP . "td", false);
  reclass($phpinfo, "th", $cP . "th", false, " ");
  reclass($phpinfo, "th", $cP . "th", false);
  reclass($phpinfo, "hr", $cP . "hr", true, " ");
  reclass($phpinfo, "pre", $cP . "pre", false);
  // Note no change to <h1 class="p"> in phpinfo()
  reclass($phpinfo, "h1", $cP . "h1");
  reclass($phpinfo, "h2", $cP . "h2");
  $phpinfo = preg_replace('/<div class="center">/',
            "<div class='{$cP}center'>", $phpinfo);

  return $phpinfo;
}

function reclass (&$phpinfo, $elem, $toClass,
                  $startOfLineP=true, $delim=">") {
  $phpinfo = preg_replace("/" .
    ($startOfLineP ? "^<" : "<") . "$elem$delim/" .
    ($startOfLineP ? "m" : ""),
    "<$elem class=$toClass$delim", $phpinfo); }

function redeclareClass ($aClassNames, &$phpinfo,
                                     $classPfx) {
  foreach ($aClassNames as $oC)	  // $oC = oldClass
    $phpinfo = preg_replace(
        "/^\\.?$oC (.*)\\}/m",
        ".$classPfx$oC $1}", $phpinfo); }

function xferCSS ($srcElem, $destElem, &$phpinfo) {
  preg_match ("/^$srcElem { ?(.*)\\}/m",
               $phpinfo, $aM, PREG_OFFSET_CAPTURE);
  $CSS = $aM[1][0]; $mL = strlen($aM[0][0]);
  // next line longer to account for possible
  // space (' ?') in 1st line
  $phpinfo = substr_replace ($phpinfo, "",
            $aM[1][1]-($mL-(strlen($CSS))), $mL+1);
  $phpinfo = preg_replace(
     "/^($destElem {)(.*)\\}/m",
     "$1$2 $CSS}",$phpinfo); }
?>


Note that all the features described in the original report have returned to the top table: it has thick light borders, a yellow background, serif fonts, and row 2, cell 2 has only one line

Csaba
 [2005-11-24 13:38 UTC] johannes@php.net
Still just an debugging tool. Create an patch and maybe 
someone applies it... 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC