Problems with function return value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tobierre

    Problems with function return value

    Hi all,

    Help, I'm stuck! I've written the below function as part of my form data
    filtering steps and for some reason It won't return the right value!

    Can someone take a little look and tell me if you can spot any errors?

    regards Tobierre

    PHP Code:
    function Stop_Form_Injec tion($post, $length)
    {
    $post = strtolower($pos t); //change input to lower case for search
    purposes

    //Check form input is allowable length
    $length = strlen($post) - $length;
    ($length > 0) ? $filter[] = $length: $filter[] = false; //if form input
    too long set false

    $filter[] = strpos('to:', $post);
    $filter[] = strpos('cc:', $post);
    $filter[] = strpos('content-type:', $post);
    $filter[] = strpos('\r', $post);
    $filter[] = strpos('\n', $post);
    $filter[] = strpos('charset =', $post);
    $filter[] = strpos('mime-version:', $post);
    $filter[] = strpos(',', $post);
    $filter[] = strpos(':', $post);
    $filter[] = strpos(';', $post);

    if(isset($filte r['0']))
    {
    $post = 'alert';
    }
    return $post;
    }

    //Should return "alert"
    $Test1 = 'hello cc:';
    $Test1 = Stop_Form_Injec tion($Test1, '15');
    print "$Test1 . '<br>'";

    //Should return "hello Joe"
    $Test2 = 'hello Joe';
    $Test2 = Stop_Form_Injec tion($Test2, '15');
    print "$Test2" . '<br>';



  • Steve

    #2
    Re: Problems with function return value

    [color=blue]
    > Help, I'm stuck! I've written the below function as part of my form data
    > filtering steps and for some reason It won't return the right value![/color]

    All of these lines:

    $filter[] = strpos('to:', $post);

    will add another array entry even if the function returns nothing, so
    your end test is always true. Recode.

    ---
    Steve

    Comment

    • Tobierre

      #3
      Re: Problems with function return value

      Hi,

      I tried rewriting with this and still not working any tips?

      (strpos('bcc:', $post) === false) ? $filter[] = false: $filter[] = true;

      if($filter[0] === true)
      {
      $post = 'alert';
      }

      return $post;


      Thanks Tobierre
      "Tobierre" <No-Reply@hotmail.c om> wrote in message
      news:11lselfpc9 tac03@corp.supe rnews.com...[color=blue]
      > Hi all,
      >
      > Help, I'm stuck! I've written the below function as part of my form data
      > filtering steps and for some reason It won't return the right value!
      >
      > Can someone take a little look and tell me if you can spot any errors?
      >
      > regards Tobierre
      >
      > PHP Code:
      > function Stop_Form_Injec tion($post, $length)
      > {
      > $post = strtolower($pos t); //change input to lower case for search
      > purposes
      >
      > //Check form input is allowable length
      > $length = strlen($post) - $length;
      > ($length > 0) ? $filter[] = $length: $filter[] = false; //if form input
      > too long set false
      >
      > $filter[] = strpos('to:', $post);
      > $filter[] = strpos('cc:', $post);
      > $filter[] = strpos('content-type:', $post);
      > $filter[] = strpos('\r', $post);
      > $filter[] = strpos('\n', $post);
      > $filter[] = strpos('charset =', $post);
      > $filter[] = strpos('mime-version:', $post);
      > $filter[] = strpos(',', $post);
      > $filter[] = strpos(':', $post);
      > $filter[] = strpos(';', $post);
      >
      > if(isset($filte r['0']))
      > {
      > $post = 'alert';
      > }
      > return $post;
      > }
      >
      > //Should return "alert"
      > $Test1 = 'hello cc:';
      > $Test1 = Stop_Form_Injec tion($Test1, '15');
      > print "$Test1 . '<br>'";
      >
      > //Should return "hello Joe"
      > $Test2 = 'hello Joe';
      > $Test2 = Stop_Form_Injec tion($Test2, '15');
      > print "$Test2" . '<br>';
      >
      >
      >[/color]


      Comment

      • Steve

        #4
        Re: Problems with function return value

        [color=blue]
        > I tried rewriting with this and still not working any tips?[/color]

        Look up the arguments for <http://www.php.net/strpos>.

        (Maybe the people arguing over in the IDE thread should look at this)

        ---
        Steve

        Comment

        Working...