Forwarding $_POST array?

Live forum: http://forum.freeipodguide.com/viewtopic.php?t=76057

JennyWren

11-06-2008 13:19:27

Is there a way to forward the contents of a $_POST array to a PHP script without explicitly calling the .phpurl==http://=http:///url file with all the ?a=b etc arguments?

I'm trying to write a page which uses phplot to display a graph, but I need to get the input from a form, do some processing, then display the graph. To display the graph I have to do

[code132ecaa369d]echo "<img src="graph.php\">";[/code132ecaa369d]

where graph.php is the graphing script. graph.php needs the form data to be able to create the graph. That code snippet exists in a separate window which is created when the user submits the form.

Suggestions?

gafdpc

11-06-2008 15:42:55

If I understand what you are saying, you need the form to submit a POST request. The main other type of request is a GET request, which will appear as results.php?a=b&c=d.

In a GET request, data will appear in $_GET, while in a POST request, data will appear in $_POST. With a POST request, the form data will not be visible in the URL.

dmorris68

11-06-2008 19:00:57

^^^ what he said.

With POST, form data is submitted in the body of the request header, rather than the URL as it is with GET.

But if you're asking how you'd pass the $_POST array around in PHP, you don't have to -- it's a super global. But it's just a regular array that could easily be copied or passed like any other array too.

If I understand what you're trying to do, however, which would be to dynamically generate images on the fly from an img tag, you still have to pass the parameters on the img tag URL line, i.e.

[code1e28f1f0935]<img src="graph.php?a=1&b=2&c=3...">[/code1e28f1f0935]

then use $_GET to get those parameters.

To use POST parameters to generate an img, you'll have to process the form submission, generate the image from the POST data, then write that image out to a static filename that you then echo back in the img tag. That can get nasty because lots of users would be generating lots of static images unless you coded some sophisticate caching algorithm that can reuse generated images. You'd also have to reap (cleanup) those images regularly.

TFOAF

11-06-2008 22:41:03

It's exactly how you're viewing this page...through a $_GET function. viewtopic.php?t=75057. t was the variable which was received through the $_GET function on a different page.

JennyWren

11-06-2008 23:23:27

I just don't like the uglified URL with all the parameters. I've done some fixin and my script now does most of the work before passing anything to the image rendering script. It's not like it's any private info or anything being sent, so it doesn't matter really if it's hidden behind a POST, GET will work fine. Just thought I'd check, I'm always trying to learn stuff I don't know.