Results 1 to 10 of 10

Thread: PHP redirect as POST (like a header: Location = )

  1. #1

    PHP redirect as POST (like a header: Location = )

    I have searched for this on the forums and didn't find anything on this one so here goes...

    I am using Send Studio to manage my website's newsletter. I am trying to implement the collection of subscribers using a flash form. When I submit the form from flash, I have to send the variables to this .php page I am trying to code. The purpose of this .php page is to parse the info from flash and send it straight on to the Send Studio script. So I need this .php page to basically do a header redirect...but it has to be done by POST.

    Specifically, the vars coming from flash need to hit my .php page and essentially "fill out" the following form and submit it:

    HTML Code:
    <form action="http://www.scripturl.com/users/form.php?FormID=XX" method="post">
    <p>Your Email Address: <input type="text" name="Email" value="" size="30"></p>
    <p><input type="hidden" name="SelectLists[1]" value="YES">
     <select name="Format">
       <option value="1">Text</option>
       <option value="2" SELECTED>HTML</option>
     </select>
    </p>
    <input type="hidden" name="FormCode" value="blahblahblahblahblah">
    <p>First Name: <input value="" id="Fields[1]" name="Fields[1]" type="text"></p>
    <p><input type="submit" value="Subscribe"></p>
    </form>
    Anyone know how to do this? I have seen some info floating around that says to do a redirect like this you have to use fsockopen -- but this is beyond my skill level.

    Any and all help is greatly appreciated.

  2. #2
    I think you could use javascript and its something like:
    HTML Code:
    <script type="text/javascript" language="javascript">
    <!--
    this.document.yourformtitle.send();
    -->
    </script>

  3. #3
    Quote Originally Posted by evildrummer View Post
    I think you could use javascript and its something like:
    HTML Code:
    <script type="text/javascript" language="javascript">
    <!--
    this.document.yourformtitle.send();
    -->
    </script>
    Hi...thanks for the reply.

    The page needs to be .php.

    I am not "leaving" the .swf and going to a new page. The processing of the data is going on in the background and I need the script to be awaiting a response from the MySQL DB so I can send it back to the .swf via the .php page. But I can handle all of that.

    I just need to have .php send the data noted above to the Send Studio script for processing, via the form, again, noted above.

  4. #4
    No one? All the people on this message board far smarter than myself and no one has an answer?

    I am certain I am not the first person to need this done. Someone hook me up, please

  5. #5
    i've been thinking about this and no straight forward answer comes to mind. i think the best idea is just copying your Send Studio script to a separate php file, accept the vars there from flash (not POST) and have it do the submission.

  6. #6
    You can use cURL for this. Check out the curl_x function set in PHP, and maybe read up on some tutorials about it. You'll have it running in no time
    Wait, what?

  7. #7
    Quote Originally Posted by bwh2 View Post
    i've been thinking about this and no straight forward answer comes to mind. i think the best idea is just copying your Send Studio script to a separate php file, accept the vars there from flash (not POST) and have it do the submission.
    Not a bad suggestion...I will look into this.

    Thanks

  8. #8
    Quote Originally Posted by Voetsjoeba View Post
    You can use cURL for this. Check out the curl_x function set in PHP, and maybe read up on some tutorials about it. You'll have it running in no time
    I will definitely look into this as well.

    If anyone has worked with PayPal and used their IPN, they know that what I am trying to do is precisely how the PayPal script works. I just don't know enough to make sense out of it for my current needs LOL

    PHP Code:
    // read the post from PayPal system and add 'cmd'
    $req 'cmd=_notify-synch';
    $tx_token $_GET['tx'];
    $auth_token "mytokencode";
    $req .= "&tx=$tx_token&at=$auth_token";

    // post back to PayPal system to validate
    $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: " strlen($req) . "\r\n\r\n";
    //$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
    // If possible, securely post back to paypal using HTTPS
    // Your PHP server will need to be SSL enabled
    $fp fsockopen ('ssl://www.paypal.com'443$errno$errstr30);

    if (!
    $fp) {
     
    // HTTP ERROR
    } else {
     
    fputs ($fp$header $req);
     
    // read the body data
     
    $res '';
     
    $headerdone false;
     while (!
    feof($fp)) {
      
    $line fgets ($fp1024);
      if (
    strcmp($line"\r\n") == 0) {
       
    // read the header
       
    $headerdone true;
      } else if (
    $headerdone) {
       
    // header has been read. now read the contents
       
    $res .= $line;
      }
     }

     
    // parse the data
     
    $lines explode("\n"$res);
     
    $keyarray = array();
     if (
    strcmp ($lines[0], "SUCCESS") == 0) {
      for (
    $i=1$i<count($lines);$i++){
      list(
    $key,$val) = explode("="$lines[$i]);
      
    $keyarray[urldecode($key)] = urldecode($val);
     }
     
    // check the payment_status is Completed
     // check that txn_id has not been previously processed
     // check that receiver_email is your Primary PayPal email
     // check that payment_amount/payment_currency are correct
     // process payment
     
    $firstname $keyarray['first_name'];
     
    $lastname $keyarray['last_name'];
     
    $itemname $keyarray['item_name'];
     
    $amount $keyarray['mc_gross'];

     }
     else if (
    strcmp ($lines[0], "FAIL") == 0) {
     
    // log for manual investigation
     
    }
    }
    fclose ($fp);
    ?> 

  9. #9

    did you ever figure this out, I'm looking to do the same..?

    did you ever figure this out, I'm looking to do the same..?

  10. #10
    Hello there, this is years after, but I found out (after days of research) that the form redirection is not possible, not at least consitently (301 redirects are not well implemented)
    here's why http://www.linuxquestions.org/questions/programming-9/[php]-header-redirect-with-post-vars-613264/
    but, I managed to do something like that using cURL and making the exec to return what was responded.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012