Bendoon Posted February 6, 2014 Share Posted February 6, 2014 Hi, Im making a basic encryption program and have the encryption side working, but want to add in the feature to "decrypt" the encoded message if need be. Im using the POST method so that my program outputs to the same page that the form is on. I have tried the following : if ( isset($_POST["decrypt"]) ) { echo $_SESSION[$old_ascii]; } if ( $key < 1 || $key > 125 ) { echo "Please enter a key between 1 and 125</br>"; } else { foreach ( $userText as $old_ascii ) { echo $new_ascii = chr(imp_circular_position(32,126, ord( $old_ascii ), $key)); $_SESSION[$old_ascii] .= $old_ascii; } All i really want to do is store the users first entered text and relay that when the decrypt button is pressed the code for that is : <div id="buttons"> <input type="submit" value="Encrypt" name="Encrypt" /> <input name="decrypt" type="submit" value="De-crypt" /> </div> if( isset($_POST["userText"]) && $_POST["key"] ) { if( empty($_POST["userText"]) || empty($_POST["key"]) ) { die("Please enter a key between 1 and 125 and enter some secret message for me to encrypt!</br>"); } $userText = $_POST["userText"]; $key = $_POST["key"]; } If anyone could help with this id really appreciate it , so all i want to do is store the text first entered in a variable if I was using GET then it would be easy but this is my first time outputting text to the same page as the form and am a little lost! Thanks! Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted February 6, 2014 Share Posted February 6, 2014 Usage of $_GET and $_POST is basically identical in terms of using the vars. So, since you think it is easy to use GET, just substitute with POST. Quote Link to comment Share on other sites More sharing options...
Bendoon Posted February 6, 2014 Author Share Posted February 6, 2014 OK so yeah got that working to some extent didnt realise it was similar, but the button will only display the text if the text is in the textarea and then the button is pressed. It seems like when i store the string into a variable when the decrypt button is pressed the value is wiped? Quote Link to comment Share on other sites More sharing options...
Bendoon Posted February 6, 2014 Author Share Posted February 6, 2014 ok so the program needs me to have text in the textarea for the button to display the text thats in it, its like the variable im storing the entered string into is wiping when i press the decrypt button.... code : if ( isset($_POST["decrypt"]) ) { echo $userText; } and this is how im getting the data above : if( isset($_POST["userText"]) && $_POST["key"] ) { if( empty($_POST["userText"]) || empty($_POST["key"]) ) { die("Please enter a key between 1 and 125 and enter some secret message for me to encrypt!</br>"); } $userText = $_POST["userText"]; $key = $_POST["key"]; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.