URL as URL's get parameters - problem with “&”

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 06:36:36

You need to encode the value with the percent-encoding.

If you’re using PHP, use rawurlencode (or urlencode if application/x-www-form-urlencoded is expected):

$url = 'http://www.google.com?q=adsf&lang=en';
echo 'script.php?file='.rawurlencode($url);

You need to URL encode the entire URL that you are passing as a parameter to another url (your script). %26 is the correct encoding for an &. Just make sure you decode it server-side before using it. You don't say what language(s) you're using, but most, inc javascript and php have native URL encoding functions.

Try to encode every special character like this:

script.php?file=http%3a%2f%2fwww.google.com%3fq%3dadsf%26lang%3den&id=123

although it might be better and easier to use rawurlencode().

Also, read this about URL encoding.

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