By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,067 Members | 1,818 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,067 IT Pros & Developers. It's quick & easy.

Sending data from a form to two seperate pages?

P: 5
I have a simple form and would like the data sent to two different pages. Actually I only need the data sent to one page and the user sent to another page.
For example user is at page1.php (which contains the form). Once the user submits the form, the data is sent to page2.php and the user is redirected to page3.php.

This is most likely a javascript solution but since I'm always using php I figured I'd post it here.
May 24 '07 #1
Share this Question
Share on Google+
3 Replies


pbmods
Expert 5K+
P: 5,821
Once you're finished processing the form data, use a header redirect:

Expand|Select|Wrap|Line Numbers
  1. header('Location: page3.php');
  2. exit;
  3.  
Note that this will only work if your script *does not output ANYTHING to the browser*! This includes any leading spaces before the first <?php tag in your document.
May 24 '07 #2

P: 5
Once you're finished processing the form data, use a header redirect:

Expand|Select|Wrap|Line Numbers
  1. header('Location: page3.php');
  2. exit;
  3.  
Note that this will only work if your script *does not output ANYTHING to the browser*! This includes any leading spaces before the first <?php tag in your document.

Yes that would work. But unfortunately I would like to post to someone elses site but have my user go to one of my pages.
May 24 '07 #3

pbmods
Expert 5K+
P: 5,821
Yes that would work. But unfortunately I would like to post to someone elses site but have my user go to one of my pages.
Ah. Well then, you'll be wanting to use either cURL or fopen, depending on how you need to send the data. If it s/b POST'd, then you'll have to use cURL, and I know just about nothing about it. Though there is a pretty good resource here.

If you can pass the variables via GET, then you can use file_get_contents to send the form variables, something like this:

Expand|Select|Wrap|Line Numbers
  1. $response = file_get_contents("http://somesite.dom/formprocessor.php?var1=val1&you=get&the=idea", 'r');
  2.  
Then parse $response (or whatever you decided to call it ~_^) to verify a correct submission, and redirect on success.
May 25 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.