最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Special Characters in URL query string - Stack Overflow

programmeradmin1浏览0评论

I have a situation where the user is able to enter any characters they want in a URL query string.

Example:

http://localhost/default.aspx?ID=XXXX

http://localhost/default.aspx?ID=&XXXX

http://localhost/default.aspx?ID=#XXXX

The web page must accept the ID parameter as it is no matter what the characters are. However certain special characters such as ampersand(&) and pound(#) creates problems. How can I accept them as is?

I have a situation where the user is able to enter any characters they want in a URL query string.

Example:

http://localhost/default.aspx?ID=XXXX

http://localhost/default.aspx?ID=&XXXX

http://localhost/default.aspx?ID=#XXXX

The web page must accept the ID parameter as it is no matter what the characters are. However certain special characters such as ampersand(&) and pound(#) creates problems. How can I accept them as is?

Share Improve this question asked Jul 19, 2011 at 15:55 m0gm0g 9692 gold badges15 silver badges33 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 8

This:

encodeURIComponent(uri)

Where uri is the component after the ?ID=

If the user is entering the query string, they must properly encode the query string first. If you are creating the query string yourself, such as from a form submission, you will need to use a URL encode method.

Encode your URL HttpServerUtility.UrlEncode Method (String)

Edit: following your comment, you want to get query String value of ID

 String id = Request.QueryString["ID"];

Use

userinput = escape(userinput)

then, in PHP:

$userinput = urldecode($_GET['id'])

or in JS:

userinput = unescape(userinput)
发布评论

评论列表(0)

  1. 暂无评论