how to use stripslashes()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • omerbutt
    Contributor
    • Nov 2006
    • 638

    how to use stripslashes()

    hi there i am working on a project based on php mysql and html now as i was using an more secure method to authenticate login information than simply getting the post variables and comparing it with the data base i came accross different functions like

    isset()
    empty()
    stripslashes()

    i got it right till isset and empty but when working with stripslashes i am not getting it right ,as far as i know that the purpose of stripslashes() is to remove any extra

    ' " / and \ etc


    but as i tried to use it and in username input field i entered
    \omer and tried to echo it after using stripslashes($_ POST['FIELD_NAME']); it still shows the" \ " in it
    My code is here
    [code=php]
    <?
    $msg="";
    if(isset($_POST['Submit'])){
    if(!empty($_POS T["l_name"]) && !empty($_POST["l_pass"])) {
    if(isset($_POST["l_name"]) && isset($_POST["l_pass"])){
    $mem_name=strip slashes($_POST["l_name"]);
    $mem_pass=strip slashes($_POST["l_pass"]);
    echo $mem_name.'<br />'.$mem_pass;
    }
    else{
    $msg.="Good to see you Looser";
    header("Locatio n: buzz.php?msg=". $msg);
    exit();
    }
    }
    else{
    $msg.="The e-mail address / user name and password you entered did not match any accounts in our file. Please try again.";
    }
    }
    else{
    $msg.="Good to see you Looser";
    header("Locatio n: buzz.php?msg=". $msg);
    exit();
    }
    ?>
    [/code]
    any help in this regard would be highly appreciated
    regards,
    Omer Aslam
    Last edited by omerbutt; Mar 12 '08, 12:03 PM. Reason: topic name
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    stripslashes() only strips back slashes.

    I can't understand why it isn't working =/

    mysql_real_esca pe_string() is better off used. (you need to be connected to mysql for this to work)

    Comment

    • omerbutt
      Contributor
      • Nov 2006
      • 638

      #3
      Originally posted by markusn00b
      stripslashes() only strips back slashes.

      I can't understand why it isn't working =/

      mysql_real_esca pe_string() is better off used. (you need to be connected to mysql for this to work)
      yeah i am also surpeised that why isnt it working but now i have made some ammendments in my code here it is
      [code=php]
      $msg="";
      if(isset($_POST['Submit'])){
      if(!empty($_POS T["l_name"]) && !empty($_POST["l_pass"])) {
      if(isset($_POST["l_name"]) && isset($_POST["l_pass"])){
      $mem_name=$_POS T["l_name"];
      $mem_name0=strt olower($mem_nam e);
      $mem_name1=str_ ireplace("/","",$mem_name0 );
      $mem_name2=str_ ireplace(",","" ,$mem_name1);
      $mem_name3=str_ ireplace("'","" ,$mem_name2);
      $mem_name4=str_ ireplace("*","" ,$mem_name3);
      $mem_name5=str_ ireplace("and", "",$mem_nam e4);
      $mem_name6=str_ ireplace("or"," ",$mem_name 5);
      $mem_name7=str_ ireplace("where ","",$mem_name6 );
      $mem_name=trim( $mem_name7);
      echo $mem_name.'<br />'.$mem_pass;
      }
      else{
      $msg.="Good to see you Looser";
      header("Locatio n: buzz.php?msg=". $msg);
      exit();
      }
      }
      else{
      $msg.="The e-mail address / user name and password you entered did not match any accounts in our file. Please try again.";
      }
      }
      else{
      $msg.="Good to see you Looser";
      header("Locatio n: buzz.php?msg=". $msg);
      exit();
      }
      [/code]
      but one thing that how could i avoid
      ; and " from the entered string
      any idea?
      reagards,
      Omer

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        You could do it quicker with preg_replace
        [php]
        $replace[0] = '#and#'; // replace and
        $replace[1] = '#or#'; // replace or
        $replace[2] = '#where#'; // replace where
        $replace[3] = '#[\*;\'/\,\"]#'; // replace * ; ' , "
        echo preg_replace($r eplace, "", "*heandlalwhere o;"); // do the replacement
        [/php]

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          Or you could use this one, [php]$memname=trim(s tr_ireplace(arr ay("/",",","'","*"," and","or","wher e"),'', strtolower($mem name)));[/php]Ronald

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by ronverdonk
            Or you could use this one, [php]$memname=trim(s tr_ireplace(arr ay("/",",","'","*"," and","or","wher e"),'', strtolower($mem name)));[/php]Ronald
            Pah!
            Defeated me again.

            Comment

            • ronverdonk
              Recognized Expert Specialist
              • Jul 2006
              • 4259

              #7
              Originally posted by markusn00b
              Pah!
              Defeated me again.
              Not really, it is merely another way of solving it. ;-)

              Ronald

              Comment

              • Markus
                Recognized Expert Expert
                • Jun 2007
                • 6092

                #8
                Originally posted by ronverdonk
                Not really, it is merely another way of solving it. ;-)

                Ronald
                if str_ireplace() is case-insensitive is there any need for strtolower()?

                Comment

                • ronverdonk
                  Recognized Expert Specialist
                  • Jul 2006
                  • 4259

                  #9
                  Originally posted by markusn00b
                  if str_ireplace() is case-insensitive is there any need for strtolower()?
                  Not for the replace, but the result string is also lower case.

                  Ronald

                  Comment

                  • omerbutt
                    Contributor
                    • Nov 2006
                    • 638

                    #10
                    Originally posted by ronverdonk
                    Or you could use this one, [php]$memname=trim(s tr_ireplace(arr ay("/",",","'","*"," and","or","wher e"),'', strtolower($mem name)));[/php]Ronald
                    thanks alots guys for a bunch of help and speacially ronverdonk who gave such a reduced code of just 1 line that was reallly excellent but 1 thing is stilll there that
                    CASE 1:
                    i want to remove WHITE SPACES from the username lets say if i enter
                    "omer aslam"
                    then it should remove the space between omer AND aslam but it is not doing it
                    CASE 2:
                    and if i enter only white spaces at the end of the name
                    i.e like this "omer " then in this case it removes the spaces but not in the first case EVEN IF I USE MY TECHNIQUE OR RONVERDONK'S
                    thanks alot anyways guys that you helped me so far.
                    Any help in this regard is highly appreciated.
                    Thanks in advance,
                    regards,
                    Omer Aslam.

                    Comment

                    • Markus
                      Recognized Expert Expert
                      • Jun 2007
                      • 6092

                      #11
                      [php]
                      $memname=trim(s tr_ireplace(arr ay(" ", "/",",","'","*"," and","or","wher e"),'', strtolower($mem name)));
                      [/php]

                      Try that

                      Comment

                      • omerbutt
                        Contributor
                        • Nov 2006
                        • 638

                        #12
                        Originally posted by markusn00b
                        [php]
                        $memname=trim(s tr_ireplace(arr ay(" ", "/",",","'","*"," and","or","wher e"),'', strtolower($mem name)));
                        [/php]

                        Try that
                        THANKS ALOOOOOOOOOOOOO OOOOOOOOOT MAN you were really a THETA of PHP :D well just kiddin thats just because you have alots of experience but thats remarkable ;) i guess that was enough :D any how you really helped me out thanks alot guys again bundle of thanks for such efficient and quick reply
                        regards,
                        Omer.

                        Comment

                        • Markus
                          Recognized Expert Expert
                          • Jun 2007
                          • 6092

                          #13
                          Originally posted by omerbutt
                          THANKS ALOOOOOOOOOOOOO OOOOOOOOOT MAN you were really a THETA of PHP :D well just kiddin thats just because you have alots of experience but thats remarkable ;) i guess that was enough :D any how you really helped me out thanks alot guys again bundle of thanks for such efficient and quick reply
                          regards,
                          Omer.
                          Haha, ron was the op of that, i just tweaked it ever so slightly.

                          Remember, if there's anything else you want plucking out of the user input just add it into the array :)

                          Comment

                          • omerbutt
                            Contributor
                            • Nov 2006
                            • 638

                            #14
                            Originally posted by markusn00b
                            Haha, ron was the op of that, i just tweaked it ever so slightly.

                            Remember, if there's anything else you want plucking out of the user input just add it into the array :)
                            yeah okay i did that because i had to remove some more extra characters so i did the same, but apart from the discussion ronverdonk really helped me alot he do was OP for that :D
                            take care alots ,
                            regards,
                            Omer.

                            Comment

                            • ronverdonk
                              Recognized Expert Specialist
                              • Jul 2006
                              • 4259

                              #15
                              Consider it a joint solution. It really doesn't matter who originated what code.
                              In my opinion code should be shared freely. To me there is no such thing as 'ownership' of code, contrary to what a lot of programmers and companies think.

                              Ronald

                              Comment

                              Working...