Passing Variables from page to page without forms

Hi Guys,

Say you have 2 scripts: index.php which displays a list of items and delete.php which deletes the items (it processes the request only).

I send the IDs of the items to be deleted from Index.php to delete.php through a form but I want to send those IDs back to index.php so that I can prompt the user that he just deleted those items and present him with an undo possibility.

How do I get the IDs to index.php back from delete.php?

The only way I know how to send variables form script to script is through $_post, $_get, which require form submission and $_Session, which I don’t think suits the purpose because I’m looking for something more temporary…

Is there a way? Should I just use $_session?

I’m not looking for code, just theory.

Easiest way is a $_GET request. Since you don’t actually do any processing after this point and just want to display a message, it doesn’t really matter if a user changes things in the $_GET request

page.php?deleted=4


<?php
$display_deleted_msg = false;

if(isset($_GET['deleted'])){
     if(is_numeric($_GET['deleted']) && $_GET['deleted']>0){
          $id = $_GET['deleted'];
          $display_deleted_msg=true;
     }
}
?>
<!DOCTYPE html>
<html>
<head></head>
<body>
<? if($display_deleted_msg===true): ?><div id="delete_msg">Record ID <?php echo $id ?> has been deleted</div><?php endif; ?>
</body>
</html>

And then if you really want to get fancy, fade out the message with JavaScript.

How do you pass things to $_SESSION without submission?

No matter what you do, you’re going to have to submit something. PHP does not work in real time. (AJAX submits, just the same as any form)

You can destroy session variables as easily as you can create them, but you’re still going to have to submit them via GET or POST in order to get them into the array, unless you somehow already know what the user wants to do before you present the webpage.

You could store them in a session, a database, or pass them via get with a link like:

Return to index.php?justdeleted=5

I’d probably be cleanest to create a field in your database user table for recently deleted.

I thought about a DB approach but wouldn’t that be resource intensive? I already have a flag saying an entry is in the “recycle bin”. Once it’s deleted, it’s out and I don’t want to keep a reference to it.

It’s there a simple way to make a variable from script to script that’s destroyed as soon as it’s used?