i can not get addslashes/stripslashes to have the same effect on different servers

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

    i can not get addslashes/stripslashes to have the same effect on different servers

    This seems so simple, I can't believe its tripping me up. I've a
    database class with a query method that looks like this:


    function query($query=fa lse) {
    global $controller;
    // $query = stripslashes($q uery);
    // $query = addslashes($que ry);
    $result = mysql_query($qu ery);

    if (!$result) {
    $dbErrorMessage = mysql_error();
    $controller->error("In query(), in the class Database, our last
    query to the database failed. The query was '$query'. The database
    server returned this message: '$dbErrorMessag e' ");
    }

    return $result;
    }


    I'm working at two different companies right now, and so I'm dealing
    with 2 different servers, but I've been using this same class in all my
    code. One one server I have to uncomment the line with stripslashes. On
    the other server I need to leave it commented. Surely there is a way to
    make this code work on all servers?

  • Rik

    #2
    Re: i can not get addslashes/stripslashes to have the same effect on different servers

    lawrence k wrote:
    This seems so simple, I can't believe its tripping me up. I've a
    database class with a query method that looks like this:
    >
    >
    function query($query=fa lse) {
    global $controller;
    // $query = stripslashes($q uery);
    // $query = addslashes($que ry);
    $result = mysql_query($qu ery);
    >
    if (!$result) {
    $dbErrorMessage = mysql_error();
    $controller->error("In query(), in the class Database, our last
    query to the database failed. The query was '$query'. The database
    server returned this message: '$dbErrorMessag e' ");
    }
    >
    return $result;
    }
    >
    >
    I'm working at two different companies right now, and so I'm dealing
    with 2 different servers, but I've been using this same class in all
    my code. One one server I have to uncomment the line with
    stripslashes. On the other server I need to leave it commented.
    Surely there is a way to make this code work on all servers?
    Hard to say without knowing how the query actually get's build.
    Are you sure it's not a byproduct of those pesky magic_quotes?
    --
    Rik Wasmus


    Comment

    • Ruben van Engelenburg

      #3
      Re: i can not get addslashes/stripslashes to have the same effecton different servers

      lawrence k wrote:
      I'm working at two different companies right now, and so I'm dealing
      with 2 different servers, but I've been using this same class in all my
      code. One one server I have to uncomment the line with stripslashes. On
      the other server I need to leave it commented. Surely there is a way to
      make this code work on all servers?
      >
      Hi Lawrence,

      Just a guess: check your magic_quotes_gp c setting in php.ini. If it's
      set to on turn it off and just use stripslashes and addslashes.

      Ruben.

      Comment

      • Jerry Stuckle

        #4
        Re: i can not get addslashes/stripslashes to have the same effecton different servers

        Ruben van Engelenburg wrote:
        lawrence k wrote:
        >
        >I'm working at two different companies right now, and so I'm dealing
        >with 2 different servers, but I've been using this same class in all my
        >code. One one server I have to uncomment the line with stripslashes. On
        >the other server I need to leave it commented. Surely there is a way to
        >make this code work on all servers?
        >>
        >
        Hi Lawrence,
        >
        Just a guess: check your magic_quotes_gp c setting in php.ini. If it's
        set to on turn it off and just use stripslashes and addslashes.
        >
        Ruben.
        Yes, check your magic_quotes_gp c. But don't use addslashes on data to
        be used in a MySQL query. Use mysql_real_esca pe_string() instead.
        That's what it's for - and it is charset sensitive. addslashes() is not.

        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • lawrence k

          #5
          Re: i can not get addslashes/stripslashes to have the same effect on different servers


          Ruben van Engelenburg wrote:
          lawrence k wrote:
          >
          I'm working at two different companies right now, and so I'm dealing
          with 2 different servers, but I've been using this same class in all my
          code. One one server I have to uncomment the line with stripslashes. On
          the other server I need to leave it commented. Surely there is a way to
          make this code work on all servers?
          >
          Hi Lawrence,
          >
          Just a guess: check your magic_quotes_gp c setting in php.ini. If it's
          set to on turn it off and just use stripslashes and addslashes.

          I'm sure it is a product of magic_quotes_gp c, but isn't there a way to
          get PHP to work intelligently regardless of settings in the php.ini? I
          can't casually change the php.ini on either server since there is 30
          client sites on one machine and over 100 on the other machine. For all
          I know they've code on their sites that depend on whatever the current
          setting is for magic_quotes_gp c. I'd potentially be breaking live sites
          if I changed the php.ini file. That's just not an option. But isn't
          there a way to work around magic_quotes_gp c? I thought magic_quotes_gp c
          was suppose to work transparently?

          Comment

          • Todd

            #6
            Re: i can not get addslashes/stripslashes to have the same effecton different servers

            lawrence k wrote:
            Ruben van Engelenburg wrote:
            >lawrence k wrote:
            >>
            >>I'm working at two different companies right now, and so I'm dealing
            >>with 2 different servers, but I've been using this same class in all my
            >>code. One one server I have to uncomment the line with stripslashes. On
            >>the other server I need to leave it commented. Surely there is a way to
            >>make this code work on all servers?
            >>>
            >Hi Lawrence,
            >>
            >Just a guess: check your magic_quotes_gp c setting in php.ini. If it's
            >set to on turn it off and just use stripslashes and addslashes.
            >
            >
            I'm sure it is a product of magic_quotes_gp c, but isn't there a way to
            get PHP to work intelligently regardless of settings in the php.ini? I
            can't casually change the php.ini on either server since there is 30
            client sites on one machine and over 100 on the other machine. For all
            I know they've code on their sites that depend on whatever the current
            setting is for magic_quotes_gp c. I'd potentially be breaking live sites
            if I changed the php.ini file. That's just not an option. But isn't
            there a way to work around magic_quotes_gp c? I thought magic_quotes_gp c
            was suppose to work transparently?
            >
            if (get_magic_quot es_gpc()) {
            doSomething();
            } else {
            doSomethingelse ();
            }


            OR

            If your server is apache you could add the following to your .htaccess file:

            php_flag magic_quotes_gp c off

            Comment

            Working...