Latest Snippets

Postback - showModalDialog

You'll notice if you do a postback/submit within a dialog window in IE, it posts...

General snippet posted by Christoff Truter on 2009-09-23 07:19:57
View Snippet

 

Set Maximum Request Size

In your web.config, find the system.web node and add the httpRuntime child node,...

ASP.net snippet posted by Christoff Truter on 2009-07-29 11:55:22
View Snippet

 

Force site to run in IE7 Compatibility mode

Recently we developed an intranet application simply using all the microsoft com...

General snippet posted by Christoff Truter on 2009-07-22 10:00:19
View Snippet

 

FileSystemWatcher example

An example of how to monitor the filesystem using the filesytemwatcher class in ...

C# snippet posted by Christoff Truter on 2009-06-27 22:08:12
View Snippet

 

Format Currency

Format a string into a currency format, similar to the FormatCurrency function i...

Javascript snippet posted by www.sonofsofaman.com on 2009-06-12 09:52:50
View Snippet

 

MD5 hash

The following snippet demonstrates how to create a MD5 hash using SQL 2005...

MSSQL snippet posted by Christoff Truter on 2009-06-11 10:01:37
View Snippet

 

Register Globals off

If you don't have access to your php.ini or the ability to set register_globals ...

PHP snippet posted by Christoff Truter on 2009-06-09 11:47:26
View Snippet

 

Table Variables

SQL 2000 introduced an alternative to temporary tables called table variables....

MSSQL snippet posted by Christoff Truter on 2009-06-08 15:59:55
View Snippet

 

MD5 hash

Calculate the MD5 hash of a given string...

C# snippet posted by Christoff Truter on 2009-06-02 14:08:47
View Snippet

 

Row Number

How to number rows of a query using mysql...

MySQL snippet posted by Christoff Truter on 2009-05-22 14:36:53
View Snippet

 

Snippets

Register Globals off

If you don't have access to your php.ini or the ability to set register_globals via your .htaccess, the following snippet will do the trick.

You'll need to execute this function just before everything else executes on your page (but after session_start())

Source:
http://www.php.net/manual/en/faq.misc.php#faq.misc.registerglobals



<?php
// Emulate register_globals off
function unregister_GLOBALS()
{
    if (!ini_get('register_globals')) {
        return;
    }
 
    // Might want to change this perhaps to a nicer error
    if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) {
        die('GLOBALS overwrite attempt detected');
    }
 
    // Variables that shouldn't be unset
    $noUnset = array('GLOBALS',  '_GET',
                     '_POST',    '_COOKIE',
                     '_REQUEST', '_SERVER',
                     '_ENV',     '_FILES');
 
    $input = array_merge($_GET,    $_POST,
                         $_COOKIE, $_SERVER,
                         $_ENV,    $_FILES,
                         isset($_SESSION) && is_array($_SESSION) ? $_SESSION : array());
 
    foreach ($input as $k => $v) {
        if (!in_array($k, $noUnset) && isset($GLOBALS[$k])) {
            unset($GLOBALS[$k]);
        }
    }
}
 
unregister_GLOBALS();
 
?>
 


posted by Christoff Truter on 2009-06-09 11:47:26

 

Comments


Write a comment

* *
*

* Required fields

Latest PHP Snippets

Register Globals off

If you don't have access to your php.ini or the ability to set register_globals ...

posted by Christoff Truter on 2009-06-09 11:47:26
View Snippet

 

Force file download

The following code will prompt the user to download a file, rather than simply a...

posted by Christoff Truter on 2009-05-07 13:14:10
View Snippet

 

Unify Exception models

PHP has this annoying feature of having two exception models, the following snip...

posted by Christoff Truter on 2009-05-05 16:59:36
View Snippet

 

IIS REQUEST_URI Issue

Ever deployed a PHP solution to an IIS server, only to find that the REQUEST_URI...

posted by Christoff Truter on 2009-05-05 13:37:50
View Snippet

 

IIS DOCUMENT_ROOT Issue

Ever deployed a PHP solution to an IIS server, only to find that the DOCUMENT_RO...

posted by Christoff Truter on 2009-05-05 13:32:04
View Snippet

 

Getter & Setter

An example of how to create getters and setters in PHP. Firstly we create an ...

posted by Christoff Truter on 2009-03-16 15:06:18
View Snippet

 

ArrayAccess: Creating an Indexer

For you guys familiar with indexers in C#, in PHP you get an interface called Ar...

posted by Christoff Truter on 2009-03-15 20:41:57
View Snippet

 

Simple recursion

This is a very simple recursive function, that i've adapted (minus the potential...

posted by Christoff Truter on 2009-02-21 19:54:52
View Snippet

 

Get the total days in a month

For anyone still using PHP 3, here is an easy way to get the total days in a mon...

posted by Christoff Truter on 2009-02-16 13:53:44
View Snippet

 

Deep copy/clone an object

Want deep cloning without too much hassle? Source: http://www.php.net/lan...

posted by Cheetah on 2009-02-16 12:14:33
View Snippet