Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Magic quotes?

  1. #1
    Regular Coder
    Join Date
    Jul 2003
    Posts
    262
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Magic quotes?

    edited.

    I'd like to know if there is a more elegant way to do this without the IF block and all the repeating setting of variables. I've got some update queries that are pretty big already.

    From the manual:
    Code:
    if (!get_magic_quotes_gpc()) { 
       $lastname = addslashes($_POST['lastname']); 
    } else { 
       $lastname = $_POST['lastname']; 
    }
    Last edited by mothra; 07-18-2005 at 03:35 AM.

  • #2
    Regular Coder
    Join Date
    May 2004
    Location
    Berkeley, California Age: 15
    Posts
    398
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sure you could use some ternary operators:

    PHP Code:
    $lastname = (get_magic_quotes_gpc()) ? $_POST['lastname'] : addslashes($_POST['lastname']); 
    Jalenack.com .:. YWDA Founder .:. Rounded Corners Maker 1.1! .:. My Blog
    The hardest thing about teaching is not knowing the right answers, but knowing the right questions - Elisabeth Klein
    Pretty buttons does not a great website make.

  • #3
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    Have you tried to use a recursive function and add slashes to all variables in $_POST?
    PHP Code:
    function deepAddSlashes(&$var) {
      if(
    is_array($var) || is_object($var)) {
        foreach(
    $var as $key => $value) {
          
    $var[$key] = addslashes($value);
        }
      }
      else 
    $var addslashes($var);
    }
    if (!
    get_magic_quotes_gpc()) {
      
    deepAddSlashes($_POST); // add slashes to every variable in $_POST
      
    deepAddSlashes($_GET); // same for $_GET

    dumpfi


  •  

    Posting Permissions

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