I'm trying to pass a query string containing special html chars (eg <
). I have to do
window.location.href = ".."
And on the other page, I have to retrieve this query string using PHP. But when I check it using isset()
it returns false!
For example, when i need to escape <p>
using JS like this :
function HtmlEncode(s)
{
var el = document.createElement("div");
el.innerText = el.textContent = s;
s = el.innerHTML;
return s;
}
window.location.href = "http://localhost/test.php?t="+HTMLEncode("<p>");
Now the url is: http://localhost/test.php?t=<p>
.
When i do echo isset($_GET["t"]);
, i get false
as a result.
Or even when i try this is a <p> tag
, i get $_GET["t"]
equals to this is a
.
Can anyone tell me what's happening ?
Don't use HTMLEncode()
use encodeURIComponent()
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.