In some situations, I want to redirect my user to a page with some information being posted to the page. Getting data is very easy by just extending the URL with the parameters. Is this possible with the header function. Or is there any other method of accompolishing this???
What I want to do is very simple. Instead of doing header("Location: foo.php?bar=bar"); Here, parameter bar is being passed in URL. I want it to be posted. I have a html form file, say file1.html. Its form data is submitted to a transaction file transact.php. Depending upon the data passed, transact.php may redirect to various other pages, & it needs to pass data to them. I want to pass this data using the html post method, neither URL nor via session.
All a redirect can do is tell the browser where to request the page from. As all the GET values are passed in the query string, you can include these in the new URL. The post data is being sent by the browser to the original script in a completely different way. You want to somehow tell the browser not only that it should request a different page (with the location header) but also resend the post data that it just sent to the previous script.. which you can't do. The normal way around this would be to store the data in a session so that it is not lost between page requests. Even better, unless you have a good reason not to, just do all the processing on one page - that's what includes are for. The only method I can think of to achieve what you're asking is the original transact.php script to output another HTML form containing the data and have it submit automatically onload. And if anyone had javascript disabled, they would have to manually click a "continue" submit button..
Hi Yes, this is possible, but not with the header function. If you go to www.php.net and look up "curl" you will find what you are looking for including some sample code Brew
Assuming you don't have to use a header to move the user, and assuming you're happy to require Javascript, you could always send the user a form that would POST to the correct location and then on page load submit the form via Javascript. The form itself could just have all of the fields hidden and if you wanted to, you could even have text saying something like "Hold on... redirecting you now" in case it takes a while for the page to load...
Well, I think I got what I was looking at. Only forms have the ability to post the data. Regarding curl, well, I already had a preliminary look at it. What I understood was that using curl, you can send data to a html page using get, post etc. & retrieve the target page's response within the script & then do whatever you want with that response. Am I correct with what I have understood. Moreover, can I send requests to php scripts using curl, which are executed before their response is delivered back??? And with the alternative JavaScript method some really ignited minds have suggested here, can someone guide me further on how to automatically submit the form (My guess is to raise the submit event somehow, like there's RaiseEvent in .NET)
cURL can do anything that a browser can do (basically), so yes, you can send requests to a PHP script. Remember, the client has no concept of the way the server is processing the data (that is to say, if it can send data to an HTML page, it can send data to a PHP page, an ASP page, a Perl page or any other kind of page). Regarding submitting on page load... assuming your form has a name (or maybe an ID) of 'myform', simply make your HTML body tag something like: <body onload="document.myform.submit()">
Someone suggested me streams for achieveing the same effect. But with streams, the php code in the target resource body is being outputted as is. Looks like cURL is the final word to go by!!! As I am new to cURL, I am confirming one thing again. If my php script sample.php makes a cURL call to page1.php, the server will execute page1.php's code, & return the html equivalent to sample.php, which can then display or manipulate it. But the server will not redirect the client to page1.php. It is sample.php's responsibility to open & close cURL requests; & then display the html returned from the targer resource. Is this correct????