skyrifle Posted July 7, 2014 Share Posted July 7, 2014 Hi,I am a curious fellow just beginning to use PHP. I understand the basics of what the $_GET and $_POST superglobals do, and how we can use them to retrieve data after form submission. I also know that since $_GET and $_POST are just associate arrays, we can create our own values in both $_GET and $_POST by writing statements like $_POST['variable'] = "value".I am wondering if it is at all possible to send data beyond form data by adding new key/value pairs into $_GET and $_POST. So for example, if I had a form that transferred username/password through Post, would it be possible for me to include further data by just saying $_POST['formtype'] = "house_insurance_form"?Basically what I'm getting at is trying to physically add your own data to $_POST or $_GET that you could pull from the next page where the form redirects to. In other words, can I send data beyond form data using these superglobals? I know I can do this with $_SESSION, but could I do it through $_POST or $_GET? I haven't been able to accomplish this, and I was just wondering if someone could give me an in-depth explanation of how this might work or how this is not possible. I would really really really appreciate it. Best Regards,-Sky Quote Link to comment Share on other sites More sharing options...
sasa Posted July 7, 2014 Share Posted July 7, 2014 look this Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted July 7, 2014 Share Posted July 7, 2014 Basically what I'm getting at is trying to physically add your own data to $_POST or $_GET that you could pull from the next page where the form redirects to No, any changes made to any superglobals variables (except $_SESSION) in your code will not be remembered. PHP handles the $_SESSION superglobal differently, whereby at the end of script execution it will write the data stored in that array to a file on the server. On the next page PHP will read the contents of that file and populate the contents of the $_SESSION superglobal. The only way to persist data form page to page is either query string parameters in the url, a from (using hidden input fields) or using sessions/cookies. So for example, if I had a form that transferred username/password through Post, would it be possible for me to include further data by just saying $_POST['formtype'] = "house_insurance_form"? You could define formtype as a hidden input field and give the value of house_insurance_form Example: <form method="post" action="..."> ... <input type="hidden" name="formtype" value="house_insurance_form" /> </form> Quote Link to comment Share on other sites More sharing options...
Zane Posted July 7, 2014 Share Posted July 7, 2014 (edited) POST and GET only contain the values that were sent TO the current script. Those superglobals are not consistent throughout your pages, The $_SESSION variable however, is indeed consistent, as long as you call session_start BEFORE any output to the browser. Edited July 7, 2014 by Zane Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.