1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

http post help

Discussion in 'PHP & Perl' started by Pyronix, Apr 3, 2011.

  1. Pyronix

    Pyronix Junior Member

    Joined:
    Feb 2, 2009
    Messages:
    100
    Likes Received:
    120
    Location:
    Gone To The Dark Side
    hey looking for some assistance with a little PHP

    have zero experience in php but i have been playing
    about trying some thing for past 20min

    im trying to create a form page to collect users information
    a user fills in the information on my site which use that information
    to create an account on another site as well as storing the information
    on my site

    Code:
    <?php
    
    $API_URL = "http://randomcpaoffer.com";
    
    function rest_helper($url, $params = null, $verb = 'GET', $format = 'json') {
      $cparams = array(
        'http' => array(
          'method' => $verb,
          'ignore_errors' => true
        )
      );
      if ($params !== null) {
        $params = http_build_query($params);
        if ($verb == 'POST') {
          $cparams['http']['content'] = $params;
        } else {
          $url .= '?' . $params;
        }
      }
    
      $context = stream_context_create($cparams);
      $fp = fopen($url, 'rb', false, $context);
      if (!$fp) {
        $res = false;
      } else {
        
        $res = stream_get_contents($fp);
      }
    
      if ($res === false) {
        throw new Exception("$verb $url failed: $php_errormsg");
      }
    
      switch ($format) {
        case 'json':
          $r = json_decode($res);
          if ($r === null) {
            throw new Exception("failed to decode $res as json");
          }
          return $r;
        case 'xml':
          $r = simplexml_load_string($res);
          if ($r === null) {
            throw new Exception("failed to decode $res as xml");
          }
          return $r;
      }
      return $res;
    }
         
    if (isset($_POST['firstname'])) {
        $res = rest_helper($API_URL,
            array(
            'track' => $_POST['track'],
            'First Name' => $_POST['firstname'],
            'Last name' => $_POST['lastname'],
            'email' => $_POST['email']
            'ip' => $_POST['ip'],
        ), 'POST');
        if ($res->result == "success") {
            header("Location: {$res->login*****");
            exit();
        }
    }
    ?>
    
    <? 
    if ($res->error_list) {
        print "Please correct the following errors:<br>";
        foreach ($res->error_list as $api) {
            print "$api<br>";
        }
    }
    ?>
    <form method='post'>
    <input type='hidden' name='track' value='default'>
    
    <h3>Sign Up</h3>
    First Name: <input type='text' name='firstname' value='johnsmith'><br>
    Last Name: <input type='text' name='password' value='jsmith'><br>
    Email Address: <input type='text' name='password' value='john@jsmith.com'><br>
    <br>
    IP: <input type='text' name='ip' value='111.111.111.111'><br>
    <br>
    <input type='submit'>
    </form>
    how would i get this to post the content to the api url but also post the same content to my own mysql database or sugarcrm as well as having
    the information sent to aweber or simlar for opt-in

    :breakpc1:
     
  2. Autumn

    Autumn Elite Member

    Joined:
    Nov 18, 2010
    Messages:
    2,197
    Likes Received:
    3,041
    Occupation:
    I figure out ways to make money online and then au
    Location:
    Spamville
    When the surfer POSTs your form, save the data to your mysql database (mysql_query() and mysql_fetch_row() ), and use the curl family of functions to post the data to the API and to the Aweber signup form (using curl_exec() et al).

    It's a small job for someone experienced with PHP, you might be better off posting a freelancer job about it.
     
    • Thanks Thanks x 1
  3. artizhay

    artizhay BANNED BANNED

    Joined:
    Nov 21, 2010
    Messages:
    1,867
    Likes Received:
    1,335
    All you need to do is implement your code in the
    PHP:
    if ($res->result == "success") {
            
    header("Location: {$res->login*****");
            exit();
        }
    section before it executes the redirect.

    I don't know how the Aweber API works, so I can't tell you how to send the data to them. If it was me, I would probably just use cURL and send the data with GET or POST depending on how their API works. Or you could send it via cURL to your own opt-in form so that the data is then sent to Aweber.

    But to add it to your database, you have to establish a connection - I'm sure you know that - then just run an INSERT query.

    PHP:
    if ($res->result == "success") {
            
    // need a variable for each piece of data, so just add variables
            
    $fName $_POST['firstname'];
            
    $email $_POST['email'];
            
            
    // dependant on your database structure; add fields/values as needed
            
    mysql_query("INSERT INTO `storage` (`first_name`,`email`) VALUES ('$fName','$email')");
            
    header("Location: {$res->login*****");
            exit();
        }
     
    • Thanks Thanks x 1
  4. xpwizard

    xpwizard Junior Member

    Joined:
    Nov 6, 2010
    Messages:
    198
    Likes Received:
    122
    Judging by your $API_URL call your wanting to post the data to a cpa offer...

    Just a heads up about this, curl uses your servers IP if you didn't know that ;) So unless you have a deal with the advertiser to use a post, then none of your leads will count and you'll be banned before your first payout.

    Also, last time I checked Aweber doesn't allow a post. You must use their signup form.
     
  5. Pyronix

    Pyronix Junior Member

    Joined:
    Feb 2, 2009
    Messages:
    100
    Likes Received:
    120
    Location:
    Gone To The Dark Side
    The offers allow posting data ;)
     
  6. Autumn

    Autumn Elite Member

    Joined:
    Nov 18, 2010
    Messages:
    2,197
    Likes Received:
    3,041
    Occupation:
    I figure out ways to make money online and then au
    Location:
    Spamville
    I was thinking about how you could do the Aweber signup since for the data to be a valid optin, you have to capture the surfer's IP as well - you couldn't really do the POST to the Aweber form using curl from your server because I'm sure Aweber would take a dim view of all of your joins coming from the same IP.

    After the POST (when you are writing to mysql and sending the API join to the offer), you could generate a little bit of javascript that populates the Aweber signup form with the right data and clicks submit (which is pretty simple - Brad's CPA redirector does an automatic form post using javascript).

    Then (after you've done the mysql and the API join), when you render the html for your "thank you" page, you insert a 1x1 pixel iframe of your Aweber join form (hosted on your own site) as well as the javascript to fill and post that form onLoad(). That way, the Aweber form is posted from the surfer's browser, so Aweber would capture their IP address rather than your server IP.

    Of course, the surfer would still have to click the confirmation email in their inbox to get added to your list, and I'm not sure how happy Aweber would be if they busted you doing it.
     
    • Thanks Thanks x 1
  7. Pyronix

    Pyronix Junior Member

    Joined:
    Feb 2, 2009
    Messages:
    100
    Likes Received:
    120
    Location:
    Gone To The Dark Side
    Autumn i could always use interspire rather than aweber to do what you suggest

    would i still be required to send them a conformation email if i was to add

    you agree from time to time we may contact you with offers we may find of intrest to you blah blah blah - yes/no

    in the form ?
     
  8. Autumn

    Autumn Elite Member

    Joined:
    Nov 18, 2010
    Messages:
    2,197
    Likes Received:
    3,041
    Occupation:
    I figure out ways to make money online and then au
    Location:
    Spamville
    I'm no expert in the legalities of mailing but my understanding is that it's legal to mail them if you say on your form that they will be mailed, and then they voluntarily optin by filling in your form and clicking submit (a single optin). A double optin would be when they confirm by clicking the link in your confirmation email. It would still be a good idea to send them a confirmation and then separate your lists into single and double optin (ie. you could still mail the people who didn't confirm, and just mail the double optins to affiliate programs that demand double optins only).

    It's "better" to get double optins and required by some ISPs and affiliate companies if you want to mail for them, but single optins are legal to mail to AFAIK... You'll get more complaints though. If you can get good deliverability mailing yourself rather than using Aweber then it would solve the head ache of trying to mimic filling in the Aweber form - you could pull the lists straight from your mysql db.

    From what I understand CANSPAM has a pretty liberal definition of what "opting in" is, but once again I'm not a lawyer.
     
    • Thanks Thanks x 1
  9. Pyronix

    Pyronix Junior Member

    Joined:
    Feb 2, 2009
    Messages:
    100
    Likes Received:
    120
    Location:
    Gone To The Dark Side
    Another thing that im curious about is how Ghost CPA captures the email of an iframe'd offer and stores it in a text
     
  10. xpwizard

    xpwizard Junior Member

    Joined:
    Nov 6, 2010
    Messages:
    198
    Likes Received:
    122
    It uses a javascript popup telling the user to confirm their email address... This then writes the email to file.

    (Don't know the exact specifics as I haven't looked into the software/code).
     
    • Thanks Thanks x 1