Zend - The PHP Company




Miscellaneous

Add Code


Query Reflector  

Type: application
Added by: inertia
Entered: 19/01/2001
Last modified: 01/12/2000
Rating: - (fewer than 3 votes)
Views: 3839
Diagnostic utility for displaying all query pairs in a table.


<?
  
# Query Reflector v1.0 by Anthony Martin (inertia@yahoo.com)
  # Written and tested on PHP version 4.0.x.

  
$vars =& ${'HTTP_' $REQUEST_METHOD '_VARS'} ;
  
$color ;
  
$base 'http://' $HTTP_SERVER_VARS['SERVER_NAME'] . $HTTP_SERVER_VARS['SCRIPT_NAME'] ;
  
$back = isset ( $HTTP_ENV_VARS['HTTP_REFERER'] ) ? $HTTP_ENV_VARS['HTTP_REFERER'] : $base ;

?>
<HTML>

  <HEAD>

    <TITLE>Query Reflector by Anthony Martin (inertia@yahoo.com)</TITLE>

  </HEAD>

  <BODY bgcolor="#f0f0f0">

    <H2>Query Reflector:</H2>

<?if ( count $vars ) ) :?>
    <TABLE border="0" bgcolor="#000000">
      <CAPTION><NOBR>Found <?=count $vars )?> pair(s):</NOBR></CAPTION>
      <TR bgcolor="#c0c0c0"><TH>Key</TH><TH>Value</TH></TR>
<?  foreach ( $vars as $key => $val ) :?>
<?    
if ( is_array $val ) ) :?>
<?    
foreach ( $val as $k => $v ) :?> 
      <TR bgcolor="<?=$color '#c0c0c0' '#d0d0d0'?>">
        <TD align="right"><?=$key?>[<?=$k?>]</TD><TD><?=$v?></TD>
      </TR>
<?    endforeach ;?>
<?    
else :?>
      <TR bgcolor="<?=$color '#c0c0c0' '#d0d0d0'?>">
        <TD align="right"><?=$key?></TD><TD><?=$val?></TD>
      </TR>
<?    endif ;?>
<?    $color
++ ;?>
<?  
endforeach ;?>
    </TABLE>
    [<A href="<?=$back?>" onClick="history.go ( -1 ) ;">Back</A>]
<?else :?>
    <H3>Script was passed no variable pairs.</H3>
    <P>Usage: add pairs to the query string of this URL, starting with a question mark (?) and separated by ampersand (&amp;).</P>
    <P>For example:</P>
<?
  $example
[] = $base '?foo=bar' ;
  
$example[] = $base '?first_name=Anthony&last_name=Martin&email=inertia@yahoo.com' ;
  
$example[] = $base '?address1=1234+Fifth+St.&address2=&city=Anytown&state=NY&postal=10000' ;
  
$example[] = $base '?field[]=foo&field[]=bar&field[]=Don%27t+panic%21' ;
  
$example[] = $base '?field[zero]=foo&field[one]=bar' ;
  
$example[] = $base '?vars=this&key=that&val=them&color=blue' ;
?>
    <UL>
<?for ( $i $i count $example ) ; $i++ ) :?>
      <LI><NOBR><CODE><A href="<?=$example[$i]?>"><?=$example[$i]?></A></CODE></NOBR></LI>
<?endfor ;?>
    </UL>
    <P>To test your forms, change the <CODE>&lt;FORM&gt;</CODE> tag so that the <CODE>action=""</CODE> argument includes this script.</P>
    <P>For example:</P>
    <PRE>
&lt;FORM action="<?=$base?>"&gt;
  &lt;INPUT type="text" name="test"&gt;&lt;INPUT type="submit"&gt;
&lt;/FORM&gt;
    </PRE>
<?endif ;?>

  </BODY>

</HTML>


Usage Example


See the example


Rate This Script





Search



This Category All Categories