Redirect with successful/error messages

Asked

Viewed 100 times

0

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

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

I’ll have to duplicate these files .php of action where I validated the user options and in each of those files.php redirect to the page I want? Seems me wrong.

How can I best resolve this situation?

1 answer

2


Use the following function

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

The php self server will take the name of the current page, not counting the paths (due to 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 at 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 with a href only as an example. It will work perfectly with Location, or others.
I hope you understand. I’m sorry I upset you, feel free to comment

  • 1

    i think that’s right. Thank you for the answer :D

  • Glad I could help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.