Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 918225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:20:21+00:00 2026-05-15T18:20:21+00:00

If this is file_1.php <?php $_POST[test_message] = Hello, world; header(Location: http://localhost/file_2.php); ?> and this

  • 0

If this is file_1.php

<?php

  $_POST["test_message"] = "Hello, world";    

  header("Location: http://localhost/file_2.php");
?>

and this is file_2.php

<html>
<head>
</head>
<body>

<?php

  if (!(isset($_POST["test_message"])))
    echo "Test message is not set";
  else
    echo $_POST["test_message"];
?>

</body>
</html>

the output is Test message is not set

Which makes me wonder if one can even write to $_POST and, having wondered that, I wonder if it is bad practice to do so. Should I just let forms with submit buttons and method=post write to $_POST for me, or is it legitimate to write to $_POST to pass data between files?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:20:21+00:00Added an answer on May 15, 2026 at 6:20 pm

    You want to use $_SESSION instead.

    $_POST is for information that has been POSTed to the current page and doesn’t maintain state between page loads, it will only be populated if you actually post something to the second file when redirecting. If you were to include the second file, rather than redirecting via a header, then what you’ve done would work since the $_POST variable would still be set.

    $_SESSION will maintain state between pages, so will accomplish what you want when redirecting.

    To use $_SESSION properly, you’ll need to call session_start(); first to begin the session. There’s more info in the PHP manual.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Codes ####### The name of this file is 'test_ajaxfn.php' ####### <?php if($_POST['var']) { $result
I'm experiencing a very odd upload problem. Here's the relevant view file: <form action=http://localhost/index.php/temp/upload/
We're having this discussion here. Which is better and why? 1) a php file
I'm new to Php/Jquery Programming, and i past all this day trying figuring how
I'm learning PHP and I don't know how to get this to even work.
If I set up an HTML page with the following form: <html> <body> <form
OK, I have this php file for my HSBC bank processing using the API,
In documentation code I see some things like this: /* * @(#)File.java 1.142 09/04/01
Having this text file : Breathing 1:-29.9396 9:-32.0895 13:-35.6787 2:-36.8527 17:-37.3622 8:-38.0584 14:-38.5265 18:-38.7567
gcc 4.1.2 c99 I have the following enum's in this file ccsmd.h : enum

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.