0
Good morning, gentlemen. It may not be a good practice, alias, it’s probably not, but I’m passing some parameters in my URL by javascript to recover in PHP.
I’m passing like this in javascript. href="Analyze? id='+ par1 +'|'+ par2 + '"
ai in the URL, it’s like, weird to understand, but until then OK. Analyze? id=122963|09.27.09%204%S%20+%200.2%B%20+%200.5%CU%20+%200.3%ZN
the two parameters separated by '|', but then the bug catches.
the moment I recover for the $_GET['id'], the following happens, I use the explode to get each of the parameters, but the second parameter, was to come like this "09.27.09 4%S + 0.2%B + 0.5%CU + 0.3%ZN", with the +signals, however, the signals do not appear, they disappeared.
I even thought about encrypting the url, but I don’t know how to do it in javascript and then decrypt it in PHP, I don’t know if it actually works, but I wanted something simpler, which in the end became difficult.
I’m waiting for an answer. Thanks in advance.
Try using
encodeURIComponent(par2)
.– Sam
you tbm can use php global variable $_SERVER['REQUEST_URI'], example $Uri = $_SERVER['REQUEST_URI'], soon after only you use methods to cut what is returned
– Luan Brito
The sign
+
is a valid character that can be used in a URL and has a meaning. If you want to pass a string that contains this character, do it with @Sam suggested, useencondeURIComponent
. Ex.:href="analyze?id=' + encodeURIComponent(par1 + '|' + par2)
– fernandosavio
Only it would be better if you did it through a form, it would avoid a lot of headache.
– fernandosavio
@fernandosavio gave it right, that’s right. THANK YOU
– Dih Centioli