Jump to content

Storing a variable for later use using POST


Bendoon

Recommended Posts

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!
 
 
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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"];
 
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.