I have a url like this https://www.example.com/index?words=中国
Then in my php code, I have a code like this
if(!empty($_GET['words']) { $words = $_GET['words'];$sql = query("Select * FROM table_name WHERE colunmn_value = '$words'") }
The issue I am having is that "$_GET['words']" value is automatically encoded before it is passed to MySQL. So instead of passing 中国 to the MySQL query, it passes %E4%B8%AD%E5%9B%BD to MySQL and this causes the query to throw an error.
Please, how can I make sure that 中国 is what is being passed to MySQL? I don't want it to be converted. I have tried using urldecode, utf-8 and none is working. Any other solution.
I believe that there will be a solution otherwise Google and other Chinese websites cannot be able to pass Chinese words to its database.
I am using $_SERVER['QUERY_STRING']
instead of $_GET
to get all my parameters. However, $_SERVER['QUERY_STRING']
encodes the string by itself. Thus, if a user sends an encoded string, it gets encoded again with $_SERVER['QUERY_STRING']
. Meaning I have to run urldecode
twice.
Encoded string: https://www.example.com/test.php?info1234=3177%3B315961%3B317451%3B315511&info3598=121618%3B136803%3B13830%3B20532
If you use the link above to submit via the URL itself. Meaning you put the parameter in yourself, you get the string (which is what I want):
https://www.example.com/test.php?info1234=3177;315961;317451;315511&info3598=121618;136803;13830;20532
However, if you submit via form, you get a doubly encoded string. So when you decode, it only decodes once, and you have to run urldecode
on it again to fully decode it:
https://www.example.com/test.php?info1234=3177%3B315961%3B317451%3B315511&info3598=121618%3B136803%3B13830%3B20532
How can I make sure I get the decoded string (I don't want to run urldecode
twice on the string, as it makes my time complexity O(2n)
. I want to try keep it at O(1)
or at the very least O(n)
. I know using urldecode
means n
every time.
<?php$a = urldecode($_SERVER['QUERY_STRING']);$b = urldecode($a);if(strpos($a, "%") != false) { echo "We had to decode twice<br>"; echo $a . "<br><br>Then to:<br>" . $b;} else { echo "Only decoded once!!<br>"; echo $a;}?><form action="test.php" method="get"> myurl: <input type="text" name="myurl"><br> <input type="submit" value="Submit"></form>
Method 1:
localhost/test.php?https://www.example.com/test.php?info1234=3177%3B315961%3B317451%3B315511&info3598=121618%3B136803%3B13830%3B20532
Method 2:
localhost/test.php
https://www.example.com/test.php?info1234=3177%3B315961%3B317451%3B315511&info3598=121618%3B136803%3B13830%3B20532
You will see you get 2 different outputs
I have a random generated string that I need to put it in a URL, so I encode it like this:
var encodedToken = System.Web.HttpUtility.UrlEncode(token, System.Text.Encoding.UTF8);
In an ASP.NET action method, I receive this token and decode it:
var token = System.Web.HttpUtility.UrlDecode(encodedToken, System.Text.Encoding.UTF8);
but these tokens are not the same. For example the ab+cd
string would encode to ab%2bcd
and decoding the result would give me the ab cd
string (the plus character changed to whitespace).
So far I have only noticed the +
character problem, there may be others.
How can I solve this issue?
I am trying to decode this URL string using PHP's urldecode function:
urldecode("Ant%C3%B4nio+Carlos+Jobim");
This is supposed to output...
'Antônio Carlos Jobim'
...but instead is ouptutting this
'Antônio Carlos Jobim'
I've tested the string in a JS-based online decoder with great success, but can't seem to do this operation server side. Any ideas?
Does anyone know of any good C++ code that does this?
Dom - Mapa strony - Prywatność - Odnośniki - Copyright © 2019 Cortex IT Ltd : Kontakt : admin @ cortexit.co.uk
Please note that by viewing our site you agree to our use of cookies (see Prywatność for details). You will only see this message once.