如何对 mysql_query 进行 EXCEL 匹配?

发布于 2024-12-18 11:32:18 字数 1768 浏览 0 评论 0原文

如何进行绝对 MySQL 查询匹配。因为如果用户试图通过短链接domain.ltd/NGV调用url或文件,它与domain.ltd/ngv发生冲突,我似乎会遇到冲突,迫使获取脚本拉取/NGV文件而不是/ngv

这里是代码MySQL 选择是否还提供了 htaccess 位

 $tag = $_REQUEST['rid'];

 $q = mysql_query("SELECT * FROM `media` WHERE `qp_tag` = '".mysql_escape_string($tag)."' LIMIT 1");

 $r = mysql_fetch_row($q);

 if(!empty($r)) {

     $f = stripslashes($r['file']);
     $t = stripslashes($r['type']);

     $c = file_get_contents($f);

     $api_html = <<<API_HTML_VIEW
     $c
             API_HTML_VIEW;

     echo $api_html;

 } else {

     $api_html = <<<API_HTML_VIEW
     We are sorry but we cannot find requested resource :(
             API_HTML_VIEW;

     echo $api_html;

 }

。htaccess 代码位

RewriteRule ^([a-zA-Z0-9-]+)/?$ api.php?rid=$1 [L,QSA]

,这是生成实际短链接的最后一段代码,这也可能是问题,因为我不确定目前是什么将事情踢回来

function qp_tag() {

     $file_tag = $_FILES['file']['name'];
     $file_uni = uniqid();
     $short = strtolower(substr(base64_encode(crc32($file_tag)), 0, 3));  

     return $short;

}

编辑:系统现在可以工作,唯一的问题是如果它是一个文件,它在选择文件时会滞后分配

 $f = $r['file'];
 $t = $r['type'];
 $s = $r['size'];
 $n = $r['name'];

 header("Pragma: public"); // required
 header("Expires: 0");
 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
 header("Cache-Control: private",false); // required for certain browsers
 header("Content-Type: ".$t."");
 header("Content-Disposition:attachment;filename=".$n."");
 header("Content-Length: ".$s);
 ob_clean(); 
 flush();

 $fp = fopen($f, "r"); 
 while (!feof($fp))
     {
         echo fread($fp, 65536); 
         flush(); // this is essential for large downloads
     }  
 fclose($fp);

How to do absolute MySQL query match. Since I seem getting collision if a user is trying to call a url or a file via short link domain.ltd/NGV which collides with domain.ltd/ngv forcing the fetch script to pull /NGV file not /ngv

Here is the code which does the MySQL selections also the htaccess bit is provided

 $tag = $_REQUEST['rid'];

 $q = mysql_query("SELECT * FROM `media` WHERE `qp_tag` = '".mysql_escape_string($tag)."' LIMIT 1");

 $r = mysql_fetch_row($q);

 if(!empty($r)) {

     $f = stripslashes($r['file']);
     $t = stripslashes($r['type']);

     $c = file_get_contents($f);

     $api_html = <<<API_HTML_VIEW
     $c
             API_HTML_VIEW;

     echo $api_html;

 } else {

     $api_html = <<<API_HTML_VIEW
     We are sorry but we cannot find requested resource :(
             API_HTML_VIEW;

     echo $api_html;

 }

.htaccess code bit

RewriteRule ^([a-zA-Z0-9-]+)/?$ api.php?rid=$1 [L,QSA]

and here is the last bit of code to generate the actual short links which also may be the problem since i am not sure whats kicking the thing back at the present moment

function qp_tag() {

     $file_tag = $_FILES['file']['name'];
     $file_uni = uniqid();
     $short = strtolower(substr(base64_encode(crc32($file_tag)), 0, 3));  

     return $short;

}

Edited: The system works now the only problem is that it lags allot on selecting file if its a file

 $f = $r['file'];
 $t = $r['type'];
 $s = $r['size'];
 $n = $r['name'];

 header("Pragma: public"); // required
 header("Expires: 0");
 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
 header("Cache-Control: private",false); // required for certain browsers
 header("Content-Type: ".$t."");
 header("Content-Disposition:attachment;filename=".$n."");
 header("Content-Length: ".$s);
 ob_clean(); 
 flush();

 $fp = fopen($f, "r"); 
 while (!feof($fp))
     {
         echo fread($fp, 65536); 
         flush(); // this is essential for large downloads
     }  
 fclose($fp);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情话墙 2024-12-25 11:32:18

如果我理解正确,您想使用 BINARY 运算符 用于区分大小写的匹配:

$q = mysql_query("SELECT * FROM `media` WHERE BINARY `qp_tag` = '".mysql_escape_string($tag)."' LIMIT 1");

这与上面的查询相同,只是我在比较中插入了单词 BINARY

请注意,如果这样做,您可能无法充分利用比较列上的任何索引。这对您来说可能根本不是问题,但如果您的表中有很多行,请考虑这一点。

If I understand you correctly, you want to use the BINARY operator for case-sensitive matching:

$q = mysql_query("SELECT * FROM `media` WHERE BINARY `qp_tag` = '".mysql_escape_string($tag)."' LIMIT 1");

This is the same as your query above except I've inserted the word BINARY in the comparison.

Note that it's possible you won't be able to take full advantage of the any indexes on the comparison column if you do this. That may not be an issue at all for you, but take it into consideration if your table has a lot of rows in it.

最冷一天 2024-12-25 11:32:18

要获得精确匹配,您可以更改排序规则 qp_tag 列上的排序规则区分大小写。这些是以 _cs 结尾的排序规则,例如 latin1_general_cs 。默认排序规则通常为 latin1_swedish_ci,不区分大小写。

To get an exact match, you can change the collation on the qp_tag column to be a case-sensitive collation. Those are the collations that end in _cs , like latin1_general_cs . The default collation is usually latin1_swedish_ci, which is case-insensitive.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文