• 0

[PHP] Pass POST data from one page to another


Question

Hi all,

I want to PASS post data from a form to a php page and then to another php page.

At the moment it does this.

1. POST to External PHP page.

2. External PHP page displays SUCCESS or ERROR.

I don't want the user to see this.

Is there a way to implement it like so:

1. POST to local PHP page

2. POST from local PHP to external PHP.

3. Load PHP response into string.

4. If string contains word ERROR then display a message on local php page.

5. Otherwise Display "submission successful"

7 answers to this question

Recommended Posts

  • 0

Hi Axel, it sounds to me like you want an Ajax call; have you considered this? It would at least cover the requirement of letting you post data to the external PHP page and retrieving back a result without moving your user off the page.

  • 0

Yo again!

I did this by doing the following. Please note I don't know how security-risky is this. But here it goes.


<?php
session_start();

$_SESSION['post_data'] = $_POST;

?>
[/CODE]

Now, on the other page

[CODE]
<?php
session_start();
$_SESSION['post_data']/// Use this as the POST variable.
?>
[/CODE]

If you want to be sure that there data is cleared then do it this way:

[CODE]
<?php
session_start();
$_SESSION['post_data']/// Use this as the POST variable.

//After finishing the code:
unset($_SESSION['post_data']);
?>
[/CODE]

Hope this helps :)

Anybody who thinks this presents a security risk please let me know, because I'm using this technique right now. Although I'm not using a sensitive information.

  • 0

I'll clarify a little bit. I'm sending the form data to https://www.formstac...forms/index.php

I don't think the Formstack API supports JSON.

I can quite easily get a webpage into a variable using php:

  $url = "https://www.formstack.com/forms/index.php"
  function get_data($url) {
  $ch = curl_init();
  $timeout = 5;
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  $data = curl_exec($ch);
  curl_close($ch);
  return $data;
}

Now is it possible to somehow forward the $_POST data in the curl request so that I get the relevant data?

I hope that makes sense.

Edit: Hi Jose_49! I don't thing that technique will work on the basis that I don't have any access to the code on the https://www.formstack.com/forms/index.php page so unfortunately I can't alter it. What do you make of my suggestion above?

  • 0

This is interesting:

http://superuser.com/questions/149329/what-is-the-curl-command-line-syntax-to-do-a-post-request

curl --data "param1=value1&amp;param2=value2" http://example.com/resource.cgi

No idea how to use this though.

  • 0

I did this by doing the following.

<snip>

You've misunderstood, one of the two pages the OP wants to send the data to is on another web service!

I'll clarify a little bit. I'm sending the form data to https://www.formstac...forms/index.php

I don't think the Formstack API supports JSON.

One way you could perhaps find out: grab the POSTman addon for Google Chrome and use it to send a request. Set the method to POST, place your json encoded string in the body (RAW mode), and set the 'Content-Type' header to 'application/json', then see what you get back.

I can quite easily get a webpage into a variable using php:

  $url = "https://www.formstack.com/forms/index.php"
  function get_data($url) {
  $ch = curl_init();
  $timeout = 5;
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  $data = curl_exec($ch);
  curl_close($ch);
  return $data;
}

Now is it possible to somehow forward the $_POST data in the curl request so that I get the relevant data?

This is the method I would suggest you use to do it, submitting to your own PHP script, then with that submitting to the other web service.

Assuming the web service accepts JSON encoded data, you could use the following code:

$data = json_encode($_POST);

$ch = curl_init('https://www.formstack.com/forms/index.php');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
	'Content-Type: application/json'
);

$result = curl_exec($ch);

If the web service does not accept JSON:

The default encoding for form data in a POST request is application/x-www-form-urlencoded. I just made a little test script, and it does not seem that PHP keeps a copy of it in this format in a server variable. The application/x-www-form-urlencoded format is described here: http://www.w3.org/TR...tml#h-17.13.4.1. It's essentially the same as query string format. e.g. forename=foo&surname=bar, and certain characters being encoded.

Thankfully though, there is no need to translate the $_POST array into an application/x-www-form-urlencoded string, you can simply give CURLOPT_POSTFIELDS an array, and it'll sort it out for you!

$ch = curl_init('https://www.formstack.com/forms/index.php');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);

This is interesting:

http://superuser.com...-a-post-request

curl --data "param1=value1&amp;param2=value2" http://example.com/resource.cgi

No idea how to use this though.

Obviously this is command line usage (I'm sure you knew that, just making sure). Note that the data is in application/x-www-form-urlencoded form, as mentioned above! You could probably pass this as a string to php's exec() function, but that could very likely be extremely insecure, so I would strongly discourage it!

  • Like 2
  • 0

Thankfully though, there is no need to translate the $_POST array into an application/x-www-form-urlencoded string, you can simply give CURLOPT_POSTFIELDS an array, and it'll sort it out for you!

$ch = curl_init('https://www.formstack.com/forms/index.php');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);

YOU SIR ARE AN ACTUAL GOD - THANK YOU SO MUCH!!!

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Euro-Office must default to ODF to be considered "genuinely European", LibreOffice argues by David Uzondu Euro-Office is a web-based collaborative office suite that positions itself as a "European sovereign alternative" to American tech companies, backed by a coalition of developers including Nextcloud, IONOS, Abilian, BTactic, OpenProject, and, more recently, Tuta. The project officially went live a couple of days ago, but not before drawing heavy fire from LibreOffice developers, who called the marketing claim that Euro-Office represents the "first open-source office suite developed in Europe" a deceptive historical inaccuracy because projects like OpenOffice and LibreOffice existed decades earlier. Now that the project has launched, LibreOffice is back with another complaint, arguing that Euro-Office cannot consider itself "genuinely European" while it pushes proprietary Microsoft defaults on users. Euro-Office had promised to improve the OpenDocument Format (ODF) back in April, but the current release still plagues users with several technical failures. For instance, the suite lacks an admin setting to enforce ODF, and mobile editors completely block ODF saves, forcing files into Microsoft's OOXML formats. Some configurations force files into read-only mode, while editing frequently corrupts document formatting or erases data. LibreOffice thinks that merely supporting a format as an afterthought does not make you a sovereign alternative, as file formats are the battleground where" digital sovereignty is won or lost." The road to the first stable release of Euro-Office has been quite bumpy due to an aggressive public fallout with OnlyOffice, from which the coalition originally forked the project. OnlyOffice struck back by accusing the coalition of violating copyright terms under its AGPLv3 branding requirements by stripping the original branding anyway and forking the code. Getting Euro-Office up and running is a bit wonky (at least for non-technical users), as there is no direct installer to grab off the web. The easiest way we learnt is by using Docker. First, pull the official Euro-Office image from the GitHub Container Registry: docker pull ghcr.io/euro-office/documentserver:latest Then, run the container with active ports and a secure JWT token, enabling the test environment: docker run -i -t -d -p 8080:80 --restart=always -e EXAMPLE_ENABLED=true -e JWT_SECRET=my_secure_jwt_secret ghcr.io/euro-office/documentserver:latest And finally, open a web browser and go to the following address: http://localhost:8080 If you are running this on a remote server, replace localhost with your server's IP address. You will see the Euro-Office test page, where you can create new text documents, spreadsheets, or presentations directly in the browser. Image via Euro-Office Nextcloud promises that proper standalone desktop versions and mobile apps will arrive in a future release.
    • It’s any of their products not just windows.
    • Google Gemini has been failing for users across the United States, Europe, and Asia since early Wednesday morning, June 10, 2026, and more than six hours into the incident Google has yet to declare a fix............. https://www.techtimes.com/articles/318152/20260610/google-gemini-outage-tops-six-hours-errors-1076-1099-worldwideflash-lite-still-answers.htm
    • Fun fact: There are more Warhammer 40k games than there are stars in the universe.
  • Recent Achievements

    • Week One Done
      FBSPL earned a badge
      Week One Done
    • One Year In
      Jim Dugan earned a badge
      One Year In
    • One Month Later
      Tommi118 earned a badge
      One Month Later
    • One Month Later
      sjbousquet earned a badge
      One Month Later
    • Week One Done
      sjbousquet earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      486
    2. 2
      PsYcHoKiLLa
      197
    3. 3
      +Edouard
      155
    4. 4
      Steven P.
      83
    5. 5
      ATLien_0
      69
  • Tell a friend

    Love Neowin? Tell a friend!