Is there any way to set a particular action based on the source page?
Ex: if the previous page is exibir.php
execute "x" or if the previous page is inserir.php
execute "y".
Is there any way to set a particular action based on the source page?
Ex: if the previous page is exibir.php
execute "x" or if the previous page is inserir.php
execute "y".
Do as follows:
Previous page:
session_register("pagina_atual");
And on the new page:
if($_SESSION['pagina_atual']=="exibir"){
pagina exibir
} else {
pagina outra
}
Because HTTP requests are isolated, we need to use other resources to point the source page. All of these involve defining an identifier of the source page that will be passed to the next page.
Some alternatives that can be explored include (it's up to you to decide which one to use in each case):
Source:
<?php
session_start();
$_SESSION['origem'] = "paginaOrigem";
Next Page:
<?php
session_start();
if ($_SESSION['origem'] === "paginaOrigem"){
// ....
}
Source:
<?php
setcookie('origem', 'PaginaOrigem');
Next Page:
<?php
if ($_COOKIE['origem'] === "paginaOrigem"){
// ....
}
Source:
<a href="paginaDestino.php?origem=paginaOrigem">Link</a>
Next Page:
<?php
if ($_GET['origem'] === "paginaOrigem"){
// ....
}
hidden
in form (if it is a POST
) Source:
<input type="hidden" name="origem" value="paginaOrigem">
Next Page:
<?php
if ($_POST['origem'] === "paginaOrigem"){
// ....
}
Considerations: Using GET
(parameter by URL) is the easiest to manipulate.
When using sessions or cookies, try clearing the contents of the variable after requesting the source page, as this can cause the next page to perform the same action twice and get some "dirt"
<?php
if ($_COOKIE['origem'] === "paginaOrigem"){
// ....
}
// Terminou de executar tudo?
setcookie('origem', null, -1);
// Ou em caso de Session
unset($_SESSION['origem']);