Table of Contents

## Generate PHP Code

This feature is only available if you hand-coded your phpLens object or used the older Grid Builder to create the phpLens object, instead of using the newer Builder for applets, where the code is always autogenerated for you.

At the top of any of the dynamic editing screens is Generate PHP Code. Clicking on it will bring up a new window with the source code for that phpLens object.

You can use this code as a basis for your own program, or archive it as a backup of your current phpLens object.

The code generated by phpLens can be broken into 2 parts. Code that must be placed before any HTML because it involves HTTP header manipulation:

    <?php
    include_once('/path/to/phplens.inc.php');
    session_start();
    // Place code above before any HTML is sent to client
    ?>

All other code can be placed anywhere in your HTML page.

If you have changed the PHP code previously, you will be glad to know that phpLens preserves code changes that involve static strings or constants. To preserve changes caused by setting variables, see Preserving Dynamic Changes below.

### Live Environment Settings

In a live environment, security is important. You can configure security with the following properties:

password | Password protect phpLens dynamic editing.
dynEdit | For stronger security, you can disable phpLens dynamic editing completely by setting this property to 0.

Other security properties can be reviewed in the Security section.

### Preserving Dynamic Changes

If you need to modify properties dynamically in your own code (typically because you need to set security parameters in a live environment) Generate PHP Code will cause problems because it will overwrite your own code. To solve this problem and preserve your code changes, put all this code in a function like this:

    function SetLens(&$lens)
    {
    global $ADMIN;
    	if ($ADMIN) $lens->dynEdit = 1;
    	else $lens->dynEdit = 0;
    }

Then set this property like this:

    	$lens = PHPLensConnect(...);
    	$lens->overrideFunction='SetLens';
    	SetLens($lens);
    	$lens->Render();

and the SetLens function call will be preserved on Generate PHP Code.