繁体   English   中英

php无法从带有特殊字符或空格的url获取mysql结果?

[英]php cannot GET mysql results from url with special characters or spaces?

我已经尝试修复此问题2天了,但无济于事。

基本上,我正在根据上一页传递的URL中的内容尝试mysql的$_GET结果。

网址是这样的: http://mydomain.com/manufacturer/abc : http://mydomain.com/manufacturer/abc

要实现此URL,我正在使用.htaccess ,它工作正常。

但是,如果网址中有empty space-或任何其他特殊字符,则我的php文件将无法从mysql数据库中获取结果。

所以这行不通:

http://mydomain.com/manufacturer/abc

或这将不起作用:

http://mydomain.com/manufacturer/abc

这也不是:

http://mydomain.com/manufacturer/a+bc

等等等等...

我使用的smarty到目前为止是一个非常简单的过程,但是现在已经涉及到这一点,事实证明这有点困难。

我的php文件看起来像这样:

if (isset($_GET['man'])) {
$man = $_GET['man'];
if( ! $stmt = $db_conx->prepare("SELECT id, man, product_name FROM `$TabelName` WHERE `man` = ?") ) {
  die( $db_conx->error );
}

$stmt->bind_param('s', $man);
if ( ! $stmt->execute() ) {
  die( $stmt->error );
}
$stmt->bind_result($id, $man, $product_name);
$stmt->store_result();

while($stmt->fetch()) {
    $value[] = array('id'=>$id, 'man'=>$man, 'product_name'=>$product_name);
}
}


// Assign this array to smarty...
$smarty->assign('man', $value);



// Assign this array to smarty...
$smarty->assign('$man', $value);

}

这是我的htaccess文件:

RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^manufacturer/([a-zA-Z0-9]+)$ manufacturers.php?manu=$1
RewriteRule ^manufacturer/([a-zA-Z0-9]+)/$ manufacturers.php?manu=$1

我已经尽一切可能尝试了urlencodeurldecode ,但似乎没有任何效果。

有人可以建议这个问题吗?

提前致谢

尝试一下:

RewriteRule ^manufacturer/(.*)/?$ manufacturers.php?manu=$1

注意/? ,您不需要第二条规则,这件事就能为您完成。

RewriteRule ^manufacturer/(.+)/?$ manufacturers.php?manu=$1

这表示在制造商/匹配之后一次或多次匹配。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM