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!
 
 

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?

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"];
 
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.