Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Question on $_POST , does it persist?

Posted on 2015-01-27
5
Medium Priority
?
164 Views
Last Modified: 2015-01-27
hi,

I am a little confused on $_POST.

I basically have a form that submits a $_POST value , and calling another php page.
Later, in a completely different php page, i'd like to reuse the $_POST that was submitted earlier, and I find that it isnt available to me.

The php.net states that its a superglobal. But it looks to me like it disappears as soon as I navigate away from the page, unlike $_SESSION. Is this true?
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 14

Assisted Solution

by:Phil Phillips
Phil Phillips earned 500 total points
ID: 40574040
The $_POST variable gets whatever data is in the POST request submitted by using the form.  That data is only available to the page that receives the POST request.

You can copy the $_POST data to the session to save that information for future requests.
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 1000 total points
ID: 40574042
You need to get a basic understanding of how HTTP works, then you'll understand why you are seeing this behavior. Ray Paseur has an introductory article on the topic:

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/A_11271-Understanding-Client-Server-Protocols-and-Web-Applications.html

The short of it is that you post to the server only exists on the server for that one request. Once the request is processed, there is no reason to keep that information. If you need to persist that information, then you move to session state--or for the hardcore, a database.

Session is used to persist information across requests.

His session article may be useful also:

http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/A_11909-PHP-Sessions-Simpler-Than-You-May-Think.html
0
 
LVL 35

Assisted Solution

by:gr8gonzo
gr8gonzo earned 500 total points
ID: 40574044
A superglobal is just a variable that can be accessed from within the scope of a function without having to explicitly bring it in. For example:

$not_a_superglobal = "foo";
$_POST["something"] = "bar";

function show_scope()
{
  echo $_POST["something"]; // shows "bar"
  echo $not_a_superglobal; // Undefined variable

  global $not_a_superglobal; // Brings it into the scope
  echo $not_a_superglobal; // "foo"  
}

In short, $_POST does not persist across pages. Only $_SESSION persists.
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 1000 total points
ID: 40574048
The term superglobals just means that those particular variables can be accessed from within anywhere inside of your application. It does not imply that they persist data  in any such way.
0
 

Author Closing Comment

by:NeverEndingFlashStories
ID: 40574054
Whoa, I blinked, and 4 comments popped up :). Thanks everyone, it confirmed what i expected - i was wondering if i had an error in my syntax.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question