代码之家  ›  专栏  ›  技术社区  ›  Justin Giboney

在条令中使用URL字段

  •  0
  • Justin Giboney  · 技术社区  · 14 年前

    我正在构建站点并计划实现OpenID。我可以从Google获得一个OpenID的URL,但是在我的查询的where子句中,条令似乎对URL做了一些有趣的事情。我怎样才能解决这个问题?

    这是功能

    /* This function queries docrtrine for a user OpenID URL
     * and returns the user object.
     */
    function getUserByUserOpenIDURL ($userOpenIDURL) {
      $q = Doctrine_Query::create()
         ->select('*')
         ->from('jsgUserOpenID as u')
         ->where('openid_url = ' . $userOpenIDURL);
    
      return $q->fetchOne();
    }
    

    这是页面上的错误

    致命错误:在/library/webserver/documents/researchpm/lib/documents/table.php:299堆栈跟踪:0/library/webserver/documents/researchpm/lib/documents/table.php(256):documents_table->initdefinition()1/library/webserver/documents/researchpm/lib/documents/connection中找不到类www.php(1126):条令表->构造('www',对象(条令连接MySQL),真)2/library/webserver/documents/researchpm/lib/distric/query.php(1934):条令连接->可获取('www')3/library/webserver/documents/researchpm/lib/distric/query.php(1732):条令查询->加载根('www'、's/researchpm/lib/distric/query.php(713):条令查询->加载('www.google')5/library/webserver/documents/researchpm/lib/distric/query/where.php(121):条令查询->parseClause(' https://www.goo …')6/library/webserver/documents/researchpm/lib/district/query/where.php(81):district_query_where->_buildsql('openid_url','=',' HTTPS://www. Goo …在/library/webserver/documents/researchPM/lib/district/table.php的第299行

    1 回复  |  直到 14 年前
        1
  •  4
  •   Larry K    14 年前

    你不能恰当地转义变量。 通过命名或位置通配符,有两种方法:

    $q = Doctrine_Query::create()
           ->select('*')
           ->from('jsgUserOpenID as u')
           ->where('openid_url = ?', $userOpenIDURL);
    

    $q = Doctrine_Query::create() 
           ->select('*') 
           ->from('jsgUserOpenID as u') 
           ->where('openid_url = :url', array("url" => $userOpenIDURL));
    

    这会正确地避开您要插入的变量,并使您的应用程序能够安全地抵御SQL注入。