1
Good morning, I’m a problem that I do not know the reason, I have a code encoded in Base64 and I inserted this code into a js variable, from php to js, it worked more perfect impossible, ai I passed this js variable to php, also worked beauty, it displays exactly the code after encoding, the problem was when decoding
I encoded like this:
$encode = base64_encode(salt.hash));
I passed to the js so:
window.localStorage.setItem("campo", "<?php echo $encode; ?>");
I switched to PHP like this:
$decode_js = "<script>document.write(localStorage.getItem('campo'))</script>";
I decoded it and displayed it like this:
echo $decode = base64_decode($decode_js);
In this echo, what it brings is something very monstrous:
That:
MGszbGk5MGlvb2Y0ZWhwdXNkc2JhYWNmOTNlZTUyZTBlNjI0ZmQ0NzNkZjUyYjVlZDE5N2Y0ODM5NTQ0OWZmN2YxZjY0ZDg2ZDgzZWQ0YjBlNmRlNTFiYTk2ZmQ2YjA1ZjU1MjI5MTFmM2Q2OWI5N2RiMGUwMzhlYTg0OWZmYzBjZThiYWQxMDMxZjUzMmRkYWI0NzFiOTAzZA
Turned out to be this:
�����hr鞞�+�ץ�ƥJ�+j�z�-zh�>)�����
Can anyone help me with anything? Grateful from now on
Have you seen if the value of decode_js is exactly the field value? Because I think you are decoding the "<script>" too
– KhaosDoctor
because @khaosdoctor also found this, and for that not to occur? Is there another way to pass the js variable to a php variable? because if I decode it before, it works, of no
– flourigh
You cannot use javascript inside PHP this way. PHP is a server language, and its execution is performed before any data reaches the browser. To send a variable to PHP, you can send a form or, in the case of a page refresh not possible, use AJAX.
– brunoapimentel
I think the means would be for you to create a cookie... It’s one of the simplest means.
– KhaosDoctor
@Khaosdoctor the problem is precisely, can not use cookie, IE hangs cookie by default, so this problem that made me think of this code up there, I caught on at this point
– flourigh
@brunoapimentel in this case, I would make an ajax to pass the variable to php as if it were a page refresh with method post in the case?
– flourigh