0

I want to send some data to a page via $_POST with redirect. Like a HTML form, something like this:

<form action="http://www.thesite.com/script/stage2.php" method="post" name="theform">
<input type="hidden" name="email" value="<?php echo $email; ?>" />
<!-- etc -->
</form>
<script type="text/javascript">document.theform.submit();</script>

The thing is that, I don't want to use JavaScript and write HTML for this. I think this is possible via CURL, but I could not put it together. How can I do that? Thanks.

late edit: I'm using session, and seems to work so far.

Arda
  • 6,756
  • 3
  • 47
  • 67
  • What have you tried so far? How about a simple google search "php curl post" – The Scrum Meister Jan 17 '11 at 07:12
  • I don't understand what you are trying to do. You post some data to some http page then send a redirect on the page being downloaded. Those are two different issues. The redirect is a one liner, as Andreyco has pointed out. This answer shows you how to pass post variables into curl. http://stackoverflow.com/questions/28395/passing-post-values-with-curl – Benbob Jan 17 '11 at 07:26
  • Seems I need more coffee :) I need to send a data processed from x.php to y.php via $_POST using CURL, but I need to be redirected to y.php like I sent a html form to y.php , I've tried some examples as given below, but they dont redirect, or i'm doing something wrong. That's where I'm stuck at. Edit: and ofc I did several google searches before asking here. – Arda Jan 17 '11 at 07:34

4 Answers4

1

Nope, it is not possible. 12345

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
0

Yes, you would do it using cUrl.

<?php
$c = curl_init();
curl_setopt($c, CURLOPT_URL, 'http://www.thesite.com/script/stage2.php');
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, 'email=' . $email);
curl_exec ($c);
curl_close ($c);
?>

Source: http://answers.yahoo.com/question/index?qid=20070414080209AA3QiTt

Dustin Wilhelmi
  • 1,769
  • 2
  • 13
  • 27
  • hmm, does this redirect after CURL sending? I already tried this, this sends but does not redirect, or maybe I'm doing something wrong – Arda Jan 17 '11 at 07:30
  • No, this only does the post. I assumed you already knew how to redirect, particularly because the question only asked how to post information. You would then perform any redirect you desire after this code. – Dustin Wilhelmi Jan 17 '11 at 16:02
  • Thanks for the respond. Well, the question is that if i redirect after posting, i need to use $_POST data while i'm on that page without storing it to session, cookie or any other method, and I can't do it if i use $_POST data after I curl and redirect with header("Location: blahblah.php");. – Arda Jan 17 '11 at 17:05
0

form data you send the next page through id like stage2.php?id= or you use window.location.herf().hop it easy to use.

imad
  • 74
  • 1
  • 6
-1

stage2.php

// - process your data here
// do whatever you want, insert data to database, send them via email..

// now redirect
header("Location {$_SERVER['HTTP_REFERRER']}");  // this will redirect you to the page you came from
Andreyco
  • 22,476
  • 5
  • 61
  • 65
  • Well thanks, but that's not what I exactly meant. This will be a multi/processed code. I'll try to explain. there are 3 stages. on each stage it sends to a php file, and php file processes and redirects due to data came from forms+processed values. so in the new stage, I need to send a post from PHP file. In short, I need exact equivalent of that HTML+JS code I gave above – Arda Jan 17 '11 at 07:21