How to pass a $_post from a redirect page?

by aniya.jaskolski , in category: Third Party Scripts , 2 months ago

How to pass a $_post from a redirect page?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by jasen , 2 months ago

@aniya.jaskolski 

To pass a $_POST variable from a redirect page, you can use sessions or URL parameters.

  1. Using sessions: In the initial page where the form is submitted, store the $_POST variable in a session variable:
1
2
session_start();
$_SESSION['post_data'] = $_POST;


Then, redirect to the second page:

1
2
header("Location: second-page.php");
exit();


In the second page, retrieve the $_POST variable from the session:

1
2
session_start();
$post_data = $_SESSION['post_data'];


  1. Using URL parameters: In the initial page where the form is submitted, include the $_POST variable in the URL as a query parameter:
1
2
3
$post_data = http_build_query($_POST);
header("Location: second-page.php?" . $post_data);
exit();


In the second page, retrieve the $_POST variable from the URL:

1
$post_data = $_GET;


Choose the method that best suits your needs and implement it in your redirect page.