PHP $_GET var with urlencode and “&” bug

a 夏天 提交于 2019-12-05 19:39:07

Apache's mod_rewrite automatically decodes urlencoded strings when it does regex matching. But it only does this once, so you should be if you urlencode your string twice. This will re-escape all of those `%' characters.

try

$link = 'http://www.mydomain.com/'.urlencode(urlencode($str)).'/1';

or stop relying on rewrite rules and use a framework that handles URL routing properly.

Oh, and there should also be htmlentities() somewhere in there.

Apache will automatically translate (decode) the path. You must use a different encoding or even double encoding. Base 64 will work.

your $str isn't setup with key=val pairs

Try $str = 'var1=substr1&var2=substr2';

Two options:

  • Urlencode the string before urlencoding the query.
  • Replace all non alphanumerical chars with a dash or underscore

As for the forbidden error are you using http auth basic or digest?

Update may mistake try using htmlentities or htmlspecialchars instead of urlencode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!