1
Is there any way to define a certain action according to the source page?
Ex: if the previous page is exibir.php execute "x" or if the previous page is inserir.php execute "y".
1
Is there any way to define a certain action according to the source page?
Ex: if the previous page is exibir.php execute "x" or if the previous page is inserir.php execute "y".
1
Because HTTP requests are isolated, we need to use other resources to point to the source page. They all involve defining an identifier of the source page that will be passed to the next page.
Some alternatives that can be explored include (it is up to you to decide which one to use in each case):
Origin:
<?php 
session_start();
$_SESSION['origem'] = "paginaOrigem";
Next page:
<?php
session_start();
if ($_SESSION['origem'] === "paginaOrigem"){
// ....
}
Origin:
<?php 
setcookie('origem', 'PaginaOrigem');
Next page:
<?php
if ($_COOKIE['origem'] === "paginaOrigem"){
// ....
}
Origin:
<a href="paginaDestino.php?origem=paginaOrigem">Link</a>
Next page:
<?php
if ($_GET['origem'] === "paginaOrigem"){
// ....
}
hidden in the form (if a POST)Origin:
<input type="hidden" name="origem" value="paginaOrigem">
Next page:
<?php
if ($_POST['origem'] === "paginaOrigem"){
// ....
}
Considerations: Use the GET (URL parameter) is the easiest to manipulate.
When using Sesssions or cookies, try to clear the contents of the variable after the request of 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']);
-2
Do it this way:
On the previous page:
session_register("pagina_atual");
And on the new page:
if($_SESSION['pagina_atual']=="exibir"){
pagina exibir
} else {
pagina outra
}
session_register is an old function that has already been removed from PHP since 5.4. Please rephrase your answer.
Browser other questions tagged php
You are not signed in. Login or sign up in order to post.
What’s the point of this? I believe there are better ways to do it.
– Diego Souza
a safer way is by using Session or even client side cookies..
– Daniel Omine
I didn’t even understand the problem...
– Jorge B.
In the previous page you make a Session to register the previous page and in the new page.. makes an if($_SESSION[x]=='display.php'){ displays such a pag } Else { displays another pag }
– Sr. André Baill
Thank you André Baill !!
– Victoralm
@Andrébaill make an answer.
– Jorge B.
Okay done. @Victoralm if you would be so kind as to accept my reply. Thank you! :)
– Sr. André Baill