About handling a get-way submission with a special character parameter _ Application tips

Source: Internet
Author: User
Tags urlencode
Once a friend encountered such a problem, a product name is A&t Plastic, in the product list produces such a join <a href= "product.asp?name=a&t Plastic" >a&t PLASTIC&LT;/A&GT, you cannot receive the exact product name when you receive this parameter on the server side.
Asked me at that time, how to solve, perhaps was busy at that time, casually told him to use the HTMLEncode method, the other side tried to tell and did not solve the problem. I did not give an answer at that time, occasionally think of is really sorry, I said wrong. Today's leisure to tidy up how to deal with get way submitted by the parameters containing special characters, to the table heart guilt.



The meaning of special special characters
————————————————————————————
Meaning URL encoding for character special characters
# used to flag a specific document location%23
% to encode special characters%25
& separating different values of variables to%26
+ denotes a space in the value of a variable%2b
\ represents directory path%2f
= used to connect keys and values%3d
? Represents the start of a query string%3f



When a key value contains some of the characters in the above list, the value cannot be received accurately.
<!--file name is 01.asp-->
<%
' Defines a string containing special characters
Str= "Parameter=#%&+\=?value' Encode using the UrlEncode method
Strurlencode=server. UrlEncode (str)
' Encode using the HTMLEncode method
Strhtmlencode=server. HTMLEncode (str)
' Show all the querysting characters
Response.Write "<b>QueryString:<b>"
Response.Write Request.QueryString
' Show the passed parameters
Response.Write "
<b>parameter is:</b> "& Str &"
"
Response.Write "<b>QueryParameter=</b>"
Response.Write Request.QueryString ("str")



%>
<HTML>
<HEAD>
<meta name= "generator" content= "Microsoft Visual Studio 6.0" >
<TITLE></TITLE>
</HEAD>
<BODY>



<p><a href= "01.asp?str=<%=strurlencode%>" >str urlencode method</a></p>
<P> </P>
<p><a href= "01.asp?str=<%=strhtmlencode%>" >str HtmlEncode method</a></p>
</BODY>
</HTML>




Show results
QueryString:
Parameter Is:parameter=#%&+\=?value
Queryparameter=
Str UrlEncode Method
Str HtmlEncode method
Click Connect 1, Result
querystring:str=parameter%3d%23%25%26%2b%5c%3d%3fvalue%3c%2fhtml%3e
Parameter Is:parameter=#%&+\=?value
Queryparameter=parameter=#%&+\=?value
Str UrlEncode Method
Str HtmlEncode method
At this time we found that the parameters of the value of the Click Connect 2, Result
Querystring:str=parameter=
Parameter Is:parameter=#%&+\=?value
Queryparameter=parameter=
Str UrlEncode Method
Str HtmlEncode method
At this point you will find that the name of the anchor is not received correctly after the #, but is interpreted as the start of the anchor point, followed by "#".



Conclusion: A string containing special characters with special functions in the above list can be used as a parameter to be passed by a Get method, which is only necessary to be processed with UrlEncode. If you do not want the viewer to see the value of the string containing the HTML tag, we can use HTMLEncode to handle it.



PHP with Function UrlEncode () can be pulled, here is not an example.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.