Reputation: 352
i did this little website to convert values to md5. but i want to save all the words entered in my database to create a sort of dictionary that i could use later. when the user clicks on the convert button the page redirects to insert the data in the table and when it redirects back to the index page the md5 value is gone and the user has to click the back button to see it. how can i make the value come back in the text box after the page's redirection?
Upvotes: 1
Views: 991
Reputation: 17481
You have several methods to do this
Keep the original string and md5 hash in a session variable. It will persist even after redirects.
Instead of using the process.php, use the index.php as the target for your form. You can check the $_POST superglobal to see if you are loading the page for the first time, or displaying previously sent values.
Put the values passed to process.php in the query string of the redirection url, so instead of
header("Location: index.php");
you do
header("Location: index.php?string=$mystring&md5=$mymd5");
Be careful though, you need to sanitize $mystring or your form would be an easy XSS bait. Thanks @machineaddict.
Upvotes: 1
Reputation: 3236
This is just to understand one method of doing it:
In your process.php
file:
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['mott'])) {
$value = $_POST['mott'];
$md5 = md5($value);
// code to insert the value and the md5 in database. remember to escape the string
//redirect the user
header('Location: showmd5.php?md5=' . $md5);
exit;
}
The showmd5.php
file:
<?php
$md5 = isset($_GET['md5']) ? $_GET['md5'] : '';
// check this md5 in database and show the value
Upvotes: 2