Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does a percent symbol in a get request break my site?

I feel pretty stupid for asking this, but I'm doing a form where the user enters some input and sometimes the input is a percent symbol, say 5%. When this gets passed along as part of a GET request, like this:

http://kburke.org/project/company_x/?id=4&var1=1&ops=23255&cashflow=25000&growth=5%25&pv=100000&roe=20&profitmargin=30&roe=80&turnover=2

I get a 404 Page Not Found error. When I remove the query string pair

&growth=5%25

the page loads fine. Can someone help explain what the problem is?

Edit: I tried removing all of the Javascript from the page and the server still craps out. I also just tried running it in MAMP as

http://localhost:8888/project/company_x/?id=4&var1=1&ops=23255&cashflow=25000&growth=5%25&pv=100000&roe=20&profitmargin=30&roe=80&turnover=2

and it worked fine. I'm wondering if it's a problem with my own server. When I open Firebug to the console and run the page, I see an error very briefly and then the 404 page loads - is there a way I can pause the redirect so I can read the error message?

like image 989
Kevin Burke Avatar asked Nov 18 '10 03:11

Kevin Burke


People also ask

What does the percent sign mean in a URL?

URL Encoding (Percent Encoding) Since URLs often contain characters outside the ASCII set, the URL has to be converted into a valid ASCII format. URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits. URLs cannot contain spaces.

How do you escape the percent sign in a URL?

URL escape codes for characters that must be escaped lists the characters that must be escaped in URLs. If you must escape a character in a string literal, you must use the dollar sign ($) instead of percent (%); for example, use query=title%20EQ%20"$3CMy title$3E" instead of query=title%20EQ%20'%3CMy title%3E' .

How do I send a percentage in a URL?

To send a % sign in a url, instead send %25 . In your case, in order for php to see a percent sign, you must pass the character string %25B6011000995504101^SB to the server.

What does the percent sign mean in HTML?

html.” Spaces and other characters that aren't allowed in a URL must be encoded using a percent sign and the hexadecimal value assigned to the character in the ISO-Latin character set. A space is assigned number 32, which is 20 in hexadecimal.


1 Answers

Check out URL ENCODING. The "%" character in a url means something special.

You encode the space character ' ' as %20 in a url. You encode the percent character '%' as %25 in a url.

So after your url gets to the script, your argument 'growth' will equal "5%".

I tried messing around with your url and it appears that your script is crashing when it tries to parse the growth argument, and your web site is hiding that crash from you by sending you to the 404 page. I'd post your script code if you need more help.

like image 153
Michael Pryor Avatar answered Nov 15 '22 07:11

Michael Pryor