Log in

View Full Version : Need php5 upgrade help again, please..



BLiZZaRD
07-29-2013, 03:52 AM
Hey,

I am getting depreciation errors because a script I have is running php4 and the server no longer supports it. I realize that php5 has no eregi support at all and instead is replaced with the pregi and preg_match functions. But I can't write that. I've lost almost all of my php skills. A little help?

I need this:



function injection_chars($s) {
// returns TRUE if 'bad' characters are found
return (eregi("\r", $s) || eregi("\n", $s) || eregi("%0a", $s) || eregi("%0d", $s)) ? TRUE : FALSE;
}


to be rewritten in php5 syntax.

Please and thank you?

traq
07-29-2013, 04:12 AM
For preg_match() (http://php.net/preg_match), the pattern looks like this:
{delimiter} {pattern} {delimiter} {options}

I use # as a delimiter because it's very rarely used in the pattern. Other good/common options are /, ~, @, etc..

You might use
<?php

function injection_chars( $s ){
// test for all characters at once by using "|" ("or").
return preg_match( '#\r|\n|%0a|%0d#',$s );
}

As an aside, there are other characters you might check for. Feed, vertical tab, and nonprintable characters.
I test for them separately (since I sometimes want to keep newlines, e.g., from textareas - after I standardize them all as \r\n, of course). Here's the patterns I use:
<?php

$REGEXP_newlines = '#([\n|\r|\f|\x0b|\x85|\x{2028}|\x{2029}]+)#u';
$REGEXP_nonprintable = '#[\x00-\x08\x0B\x0C\x0E-\x1F]#';

BLiZZaRD
07-29-2013, 04:54 AM
That first one worked, thank you!

It is just for a nice contact form that I love and works well but isn't updated anymore. I rewrote a lot of the easy php (well, what I could anyway) and this was the last error I was getting. Just tried your fix and it worked, no more errors.

Thanks again!

traq
07-29-2013, 10:18 PM
Welcome!