John Davidson

php - redirect user from page to another with a message

0 comments
Message:


I have 2 PHP pages, 'users list' and 'create a user'. if I create new user successfully the page will redirect me to 'users list' page and show the new created user. the question is how I can make 'user list' page show message like 'new user was created successfully' when redirecting the client to 'user list' page?



My Answer:
You can achieve this by passing a message as a query parameter in the URL when redirecting the user from the 'create a user' page to the 'users list' page. Here's an example of how you can do this:

1. In the 'create a user' page, after successfully creating a new user, redirect the user to the 'users list' page with a message in the URL query parameter:

php
// Create a new user
// Redirect to users list page with success message
header("Location: users_list.php?message=new_user_created");
exit();


2. In the 'users list' page, check if there is a message in the URL query parameter and display it accordingly:

php
// Check if there is a message in the URL query parameter
if(isset($_GET['message'])) {
$message = $_GET['message'];

// Display the message based on the value
if($message == 'new_user_created') {
echo "New user was created successfully!";
}
}


By following these steps, when the user is redirected from the 'create a user' page to the 'users list' page, the message 'New user was created successfully!' will be displayed on the 'users list' page.

Rate this post

4 of 5 based on 2399 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us