• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

For whom are unaware [PHP]

Joined
Feb 18, 2012
Messages
779
Reaction score
247


I must refer you to this, as I see alot of people using old functions and insecure data-receiving.

Essentially its a new way of securing post and get data in PHP 5.2

EG :
PHP:
<?php
$unfiltered_data = filter_input(FILTER_GET, ‘unfiltered_data’, FILTER_UNSAFE_RAW);
?>

I just wanted to post this so someone could learn something.
 
ex visor
Loyal Member
Joined
May 17, 2007
Messages
2,741
Reaction score
937
I suppose, but MySQLi poses anti-injection all the way with prepared statements.
I think that is honestly the way to go, tbh.
 
Joined
Feb 18, 2012
Messages
779
Reaction score
247
I suppose, but MySQLi poses anti-injection all the way with prepared statements.
I think that is honestly the way to go, tbh.

Of course, But this is for most of the users here who are beginning.

I would just hope that people can start learning some decent security in there code.

Anyways, Yes you should look into MySQLi if your looking for structured security.
 
Joined
May 23, 2008
Messages
1,071
Reaction score
574


I must refer you to this, as I see alot of people using old functions and insecure data-receiving.

Essentially its a new way of securing post and get data in PHP 5.2

EG :
PHP:
<?php
$unfiltered_data = filter_input(FILTER_GET, ‘unfiltered_data’, FILTER_UNSAFE_RAW);
?>

I just wanted to post this so someone could learn something.

Did some simple benchmarking of a few things.
PHP:
    // Average over 100,000 iterations: 10.5ms
    $a = $_GET['a'];
    
    // Average over 100,000 iterations: 27.6ms
    $a = htmlentities($_GET['a']);
    
    // Average over 100,000 iterations: 51.4ms
    $a = filter_input(INPUT_GET, 'a', FILTER_SANITIZE_STRING);
    
    // Average over 100,000 iterations: 56.8ms
    $a = filter_input(INPUT_GET, 'a', FILTER_UNSAFE_RAW);

Actual benchmark code:
PHP:
<?php
$start = microtime();

for($i = 0; $i < 100000; $i++) {
    $a = $_GET['a'];
}

$end = microtime();

$result = round($end - $start, 4);
echo 'Time Elapsed: ' . $result;
?>
To get the numbers, I benchmarked each line separately 10 times to get the average. Converted the number, which were in seconds, to milliseconds.

I would rather use code that is quicker both in execution and when actually writing the code, wherein I can read it more easily and I and everyone else reading the code actually knows exactly how it is secured; not to mention some strings don't need, or perhaps will not work even correctly with certain types of supposed security.

/2cents
 
Joined
Feb 18, 2012
Messages
779
Reaction score
247
Did some simple benchmarking of a few things.
PHP:
    // Average over 100,000 iterations: 10.5ms
    $a = $_GET['a'];
    
    // Average over 100,000 iterations: 27.6ms
    $a = htmlentities($_GET['a']);
    
    // Average over 100,000 iterations: 51.4ms
    $a = filter_input(INPUT_GET, 'a', FILTER_SANITIZE_STRING);
    
    // Average over 100,000 iterations: 56.8ms
    $a = filter_input(INPUT_GET, 'a', FILTER_UNSAFE_RAW);

Actual benchmark code:
PHP:
<?php
$start = microtime();

for($i = 0; $i < 100000; $i++) {
    $a = $_GET['a'];
}

$end = microtime();

$result = round($end - $start, 4);
echo 'Time Elapsed: ' . $result;
?>
To get the numbers, I benchmarked each line separately 10 times to get the average. Converted the number, in seconds, to milliseconds.

I would rather use code that is quicker both in execution and when actually writing the code, wherein I can read it more easily and I and everyone else reading the code actually knows exactly how it is secured; not to mention some strings don't need, or perhaps will not work even correctly with certain types of supposed security.

/2cents
I see what you did there.
Thanks.
 
Back
Top