manix Posted August 14, 2011 Share Posted August 14, 2011 Hey.. I have a form where a user inputs text stuff right and I need to encode it BEFORE sending it to the submit page, and after that I need to decode it and import it into mysql.. What I thought of was to encode it in javascript and then decode in php but after a little googling I found out that php and javascript don't actually have many encoding functions in common and I'm stuck now.. Link to comment https://forums.phpfreaks.com/topic/244797-string-encoding/ Share on other sites More sharing options...
MasterACE14 Posted August 14, 2011 Share Posted August 14, 2011 encode or encrypt? It'd be as simple as: $str = "your users input"; $encode = base64_encode($str); echo $encode; echo "<br />"; $decode = base64_decode($str); echo $decode; base64_encode() Link to comment https://forums.phpfreaks.com/topic/244797-string-encoding/#findComment-1257441 Share on other sites More sharing options...
manix Posted August 14, 2011 Author Share Posted August 14, 2011 yeah if it was that simple I wouldn't be posting, see that's the problem I don't have $str <textarea id='comment' class='writingarea'></textarea> <script type='text/javascript'> $.post('usercomments.php', { id: user id here; comment: $('#comment').val() }, function(returned) { $('#comments').html(returned).show(); }); </script> Link to comment https://forums.phpfreaks.com/topic/244797-string-encoding/#findComment-1257445 Share on other sites More sharing options...
MasterACE14 Posted August 14, 2011 Share Posted August 14, 2011 use the $_POST you're sending... $str = $_POST['userinput']; Link to comment https://forums.phpfreaks.com/topic/244797-string-encoding/#findComment-1257448 Share on other sites More sharing options...
manix Posted August 14, 2011 Author Share Posted August 14, 2011 I need to encode it BEFORE sending it to the submit page Link to comment https://forums.phpfreaks.com/topic/244797-string-encoding/#findComment-1257449 Share on other sites More sharing options...
MasterACE14 Posted August 14, 2011 Share Posted August 14, 2011 why? edit: you can base64 encode with Javascript as mentioned here... http://stackoverflow.com/questions/246801/how-can-you-encode-to-base64-using-javascript , then base64_decode() in PHP. Link to comment https://forums.phpfreaks.com/topic/244797-string-encoding/#findComment-1257450 Share on other sites More sharing options...
manix Posted August 14, 2011 Author Share Posted August 14, 2011 because when I pass cyrillic characters through jquery post ajax they get ruined, and I can't really use get method because of safety reasons (not my call) Link to comment https://forums.phpfreaks.com/topic/244797-string-encoding/#findComment-1257454 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.