Redirect with success / error messages [closed]

0

In my home I have certain options that I give to the user. Each option has as action a file in .php . After the user option is submitted and validated by the .php file, I send the user to the redirected home with a success or error message, for example: home.php?sucesso=1

The options that the user has in the home, also has the other pages. Now as I have, the user clicking an option on a page other than home is redirected to home and not to the page where he clicked the option.

I will have to duplicate these files .php of action where I validate the user options and in each of these .php redirect files to the page I want? It seems to me wrong.

How can I best resolve this situation?

    
asked by anonymous 09.02.2016 / 20:22

1 answer

2

Use the following function

$patual = end(explode("/", $_SERVER['PHP_SELF']));

The server php self, will take the name of the current page, not counting the paths (due to the explode and end).

You should then do the following: Put the variable in your php code, and in the redirect part, change the link to the variable. Example:

<a href="./<?php echo $patual; ?>/?sucesso=1">

If you are in home, the browser will read the code as follows:

  

<a href="./home.php?sucesso=1">

If you are on the profile page (example, just ein?) The browser will read:

  

<a href="./perfil.php?sucesso=1">

I put it with a href just as an example. It will work perfectly with the location, or others. I hope you understood. Sorry if I messed up, feel free to comment

    
09.02.2016 / 21:57