All HTTP requests are independent of one another. Data that you have access to includes:
- Variables passed through the URL (
$_GET
)
- Variables posted through a form (
$_POST
)
- Cookies
- Session data
Since you are opposed to using a $_GET
request, and both links go to the same page, you will need some other way to determine which link is clicked. I would recommend using a form, and passing the data through a hidden input type.
Example:
<form action='process.php' method='post'>
<input type='hidden' name='action' value='add' />
<button onClick='submit();'>
Add
</button>
</form>
<form action='process.php' method='post'>
<input type='hidden' name='action' value='delete' />
<button onClick='submit();'>
Delete
</button>
</form>
<style type='text/css'>
button {
background:none!important;
border:none;
padding:0!important;
border-bottom:1px solid #444;
cursor: pointer;
}
</style>
In your process.php
script, you will then check against $_POST['action']
to see if it's equal to "add" or "delete". The style tag I added is something I found from SO user adardesign
(*) on how to style a button like a link.
EDIT: To answer your question on whether or not you can use sessions to accomplish this, I would say that it's possible, but probably not worth it.
I would probably never decide to go this route, but what you could do is have an AJAX request which gets triggered when the user clicks one of those links. The AJAX request would call a PHP script which sets the session equal to "add" or "delete". In your success
callback, you would then redirect the user to the process.php page, where you then be able to check the value of your $_SESSION
variable. Again, it's probably not worth doing it this way, but it is possible.