PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Logan Dugenoux   reGlobal   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: reGlobals example file
Class: reGlobal
Register request vars when register_globals is off
Author: By
Last change:
Date: 20 years ago
Size: 3,156 bytes
 

Contents

Class file image Download
<?
//-------------------------------------------------------------------


//--- Needed for the class
require( 'reGlobals.php' );

//--- Check current configuration
if (ini_get('register_globals'))
{
   
?>
<font color=red size=+1>
    Register globals is on. You will see no difference you should set it to off and use this script, cause you
    have major security issues in your server. Check <?=ini_get('cfg_file_path')?> to change this value.</font>
    <br>
    <a href=http://fr.php.net/manual/fr/configuration.directives.php#ini.register-globals>http://fr.php.net/manual/fr/configuration.directives.php#ini.register-globals</a> see this official link for more info.<br>
    <br><br><hr><?
}


//--- Instructions
?>
<u>Instructions:</u><br>
1- Click 'post' and see how reGlobals() works in simple mode (compatibility mode)<br>
2- Check the checkbox and Click 'post', then open example.php, and see how the the top header is modified.<br>
&nbsp;&nbsp;&nbsp;once the header has been modified, reGlobals() is not needed anymore, and your page will work properly with register_globals = off
<?


//--- If user has posted data
if ($HTTP_POST_VARS["hasPosted"])
{
    echo
"<h2>Without reGlobals</h2>";
    echo
"\$HTTP_POST_VARS[Field1]='"; print_r( $HTTP_POST_VARS["Field1"] ); echo "'<br>";
    echo
"\$HTTP_POST_VARS[Field2]='"; print_r( $HTTP_POST_VARS["Field2"] ); echo "'<br>";
    echo
"\$HTTP_POST_VARS[Field3]='"; print_r( $HTTP_POST_VARS["Field3"] ); echo "'<br>";
    echo
"\$Field1='"; print_r( $Field1 ); echo "'<br>";
    echo
"\$Field2='"; print_r( $Field2 ); echo "'<br>";
    echo
"\$Field3='"; print_r( $Field3 ); echo "'<br>";
   
   
$modSource = false;
    if (
$HTTP_POST_VARS["modSource"])
       
$modSource = true;
   
   
//-------------------------------------
    // Use of *the* class
   
new reGlobals( $modSource );
   
    echo
"<h2>With reGlobals</h2>";
    echo
"\$HTTP_POST_VARS[Field1]='"; print_r( $HTTP_POST_VARS["Field1"] ); echo "'<br>";
    echo
"\$HTTP_POST_VARS[Field2]='"; print_r( $HTTP_POST_VARS["Field2"] ); echo "'<br>";
    echo
"\$HTTP_POST_VARS[Field3]='"; print_r( $HTTP_POST_VARS["Field3"] ); echo "'<br>";
    echo
"\$Field1='"; print_r( $Field1 ); echo "'<br>";
    echo
"\$Field2='"; print_r( $Field2 ); echo "'<br>";
    echo
"\$Field3='"; print_r( $Field3 ); echo "<br>";
   
?><br><a href=<?=$HTTP_SERVER_VARS["REQUEST_URI"]?>?again=1>-------------> Try again</a><?
   
   
if ($HTTP_POST_VARS["modSource"])
    {
       
?>
<font color=red size=+1>Check example.php source code</font>
        <?
   
}
}
else
{
//--- Permit user to post data
   
?><form method=post>
    TestField1 = <input size=30 name="Field1" value="testValue1"><br>
    TestField2 = <input size=30 name="Field2" value="testValue2"><br>
    TestField3[0] = <input size=30 name="Field3[0]" value="A"><br>
    TestField3[1] = <input size=30 name="Field3[1]" value="B"><br>
    TestField3[2] = <input size=30 name="Field3[2]" value="C"><br>
    <input type=checkBox name=modSource>Check this to modify the sourcecode of example.php<br>
    <input type=hidden name="hasPosted" value="1"><br>
    <br>
    <hr>
    <center><input type="submit" value="Post"></center>
    </form>
    <?
}

echo
"<br><hr>register_globals=".((ini_get('register_globals'))?"on":"off")."<br>";


?>