Results 1 to 4 of 4

Thread: Need php5 upgrade help again, please..

  1. #1
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default Need php5 upgrade help again, please..

    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:

    PHP Code:
    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?
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    For preg_match(), the pattern looks like this:
    Code:
    {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 Code:
    <?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 Code:
    <?php

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

  3. The Following User Says Thank You to traq For This Useful Post:

    BLiZZaRD (07-29-2013)

  4. #3
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    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!
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  5. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

Similar Threads

  1. MySQLi and the PHP5.4 breaking changes.
    By ApacheTech in forum PHP
    Replies: 1
    Last Post: 07-28-2012, 04:30 PM
  2. Replies: 3
    Last Post: 04-01-2009, 07:37 AM
  3. Zipping and Taring in php5 on Apache2
    By Strangeplant in forum PHP
    Replies: 4
    Last Post: 09-08-2008, 03:15 PM
  4. Virtual Pagination with PHP5
    By CM Tech in forum Dynamic Drive scripts help
    Replies: 3
    Last Post: 08-14-2008, 04:58 AM
  5. upgrade to php5, any issues?
    By munkynpunky in forum The lounge
    Replies: 3
    Last Post: 08-10-2007, 09:56 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •