Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Carey Brown
  • Frits Walraven

Transferring additional data through $_POST and $_GET

Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 buy 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,
Posts: 3648
Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From my understand of PHP $_GET and $_POST, these are only useful in form submissions.

$_GET enables you to get the parms from the URL (the stuff after ?)

$_POST enables you to get the form fields (visible and hidden).

Say you have 2 pages: page 1 is the form and page 2 is the PHP processing. By the time page 1 is submitted, all data is wrapped in the form ($_GET or $_POST). Adding variables to this array during transmission is impossible. Once the array is at the destination (page 2), why need to "add" or "remove" any variables? Such array is for single request, unlike $_SESSION.

Therefore, have all the variables you need in the first page's form.

Since you also mentioned redirect, say page 1 submits to page 2 do process, page 2 redirects to page 3? Have the $_GET/$_POST in page 3? Maybe for $_GET if you appending the query string to the redirection page (eg page3.php?a=123&b=456...) For $_POST... from my brief google search, it is possible. Have a look at here. According to sources, people have suggested using curl and/or javascript. I will let you figure out which one is easier to implement.

Hey, sticks and stones baby. And maybe a wee mention of my stuff:
Two software engineers solve most of the world's problems in one K&R sized book
    Bookmark Topic Watch Topic
  • New Topic