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

POST help

Discussion in 'PHP & Perl' started by dor@tehexploa, May 26, 2009.

  1. dor@tehexploa

    dor@tehexploa Registered Member

    Joined:
    Apr 25, 2009
    Messages:
    95
    Likes Received:
    25
    I'm having trouble creating an automated e-mail POST script using cURL. I'm thinking it is failing for one of two reasons:

    1. cookies aren't being deleted each time the script attempts to post a new e-mail address
    2. the content data includes a random x and y value that isn't referenced in the source

    my questions are:

    - (1) Would curl keep/delete cookies in the following code?
    for(i < whatever; i++)
    {curl_init(); curl_exec()}
    // I have proper set_opt's establishing cookie use w/
    // CURLOPT_COOKIEFILE and CURLOPT_COOKIEJAR

    - (2) if the source code doesn't contain any reference to the values used in the fields x and y and doesn't refer to any .js anywhere what could these values be?
    'Email=' . urlencode($emails[$i]) . '&x=77&y=21'
    that's an example of how i hardcoded a response

    but this combined with my suspicions above have given me results but results that indicate i've used the same IP or e-mail already which I haven't..

    if anyone wants/needs more info i can PM them
     
  2. 00CivicEX

    00CivicEX Jr. VIP Jr. VIP Premium Member

    Joined:
    Mar 3, 2009
    Messages:
    293
    Likes Received:
    214
    are you having to login to the email account? If it does then the cookie has to be a new cookie from the site on everylogin....and if you have it maybe looping the email section after loggin in then it wont work....it will need to relogin ech time. I use something like this on my cURL login:

    PHP:
    $ch curl_init(); 
    curl_setopt($chCURLOPT_URL,$login_url); 
    curl_setopt($chCURLOPT_USERAGENT$agent); 
    curl_setopt($chCURLOPT_RETURNTRANSFER1);   
    curl_setopt($chCURLOPT_FOLLOWLOCATION1); 
    curl_setopt($chCURLOPT_COOKIEFILE$cookiefile); 
    curl_setopt($chCURLOPT_COOKIEJAR$cookiefile); 
     
    $data curl_exec ($ch); 
    curl_close ($ch); 
     
    //parse the html into a DOMDocument 
    $dom = new DOMDocument(); 
    @
    $dom->loadHTML($data); 
    // grab all the on the page 
     
    $xpath = new DOMXPath($dom); 
    $inputs $xpath->evaluate("//input"); 
    //search the page for every input element 
        
    for ($i 0$i $inputs->length$i++) { 
            
    //checks the name attribute and saves the right value 
            
    $input $inputs->item($i); 
            if(
    $input->getAttribute('name') == ctid) { 
                
    $ctid $input->getAttribute('value'); 
            } 
        } 
    Then use something like this to pass the data along to the login

    PHP:
    $postfields = array( 
    'ctid' => $ctid
    'fuser'    => $username
    'fpassword' => $password
    ); 
     
    $ch curl_init(); 
    curl_setopt($chCURLOPT_URL,$login_post_url); 
    curl_setopt($chCURLOPT_USERAGENT$agent); 
    curl_setopt($chCURLOPT_POST1); 
    curl_setopt($chCURLOPT_POSTFIELDS
    http_build_query($postfields)); 
    curl_setopt($chCURLOPT_RETURNTRANSFER1); 
    curl_setopt($chCURLOPT_FOLLOWLOCATION1); 
    curl_setopt($chCURLOPT_REFERER$login_url); 
     
     
    curl_setopt($chCURLOPT_COOKIEFILE$cookiefile); 
    curl_setopt($chCURLOPT_COOKIEJAR$cookiefile); 
     
  3. dor@tehexploa

    dor@tehexploa Registered Member

    Joined:
    Apr 25, 2009
    Messages:
    95
    Likes Received:
    25
    I have a class cURL that has the following functions

    get
    Code:
    function get($url) 
    {
        $process = curl_init();
        curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
        curl_setopt($process, CURLOPT_HEADER, 0);
        curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
        if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, 
    
    $this->cookie_file);
        if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, 
    
    $this->cookie_file);
        curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($process, CURLOPT_ENCODING, $this->compression);
        curl_setopt($process, CURLOPT_TIMEOUT, 30);
        curl_setopt($process, CURLOPT_URL, $url);
        $return = curl_exec($process);
        curl_close($process);
        return $return;
    }
    post
    Code:
    function post($post_url, $referer, $data) 
    {
        $process = curl_init();
        curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
        curl_setopt($process, CURLOPT_HEADER, 1);
        curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
        if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, 
    
    $this->cookie_file);
        if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, 
    
    $this->cookie_file);
        curl_setopt($process, CURLOPT_POST, true);
        curl_setopt($process, CURLOPT_POSTFIELDS, $data);
        curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($process, CURLOPT_ENCODING, $this->compression);
        curl_setopt($process, CURLOPT_TIMEOUT, 30);
        curl_setopt($process, CURLOPT_REFERER, '$referer');
        curl_setopt($process, CURLOPT_URL, $post_url);
        $return = curl_exec($process);
        curl_close($process);
        return $return;
    }
    then i do this in a FOR LOOP that increments after using an email address from an array called $emails

    Code:
    $cc = new cURL();
    $main_page = $cc->get('http://www.thewebsite.com'');
    $post_url =     regex_post_url($main_page);
    $referer =    regex_referer($main_page);
    $data =     regex_data($main_page, $emails, $i);
    
    Then to see what I get I do:

    Code:
    echo $main_page;
    echo '<br>';
    $post_page = $cc->post($post_url, $referer, $data);
    echo $post_page;
    
    I've echo'd the $post_url, $referer, and $data to ensure I'm passing in the right stuff, but the page I'm going after always displays a Thank you for participating page. This page has come up after you've already visited and enter'd an email address in. When it is working it will go to a page that wants more information like Name, Address, etc.

    Oh and no I don't need to login to my e-mail afterwards. It's basically a simple form that takes e-mail and doesn't require a verification. I'm just kinda thrown why it isn't working. I'm really curious where they get the x and y variables though.
     
    Last edited: May 26, 2009
  4. dor@tehexploa

    dor@tehexploa Registered Member

    Joined:
    Apr 25, 2009
    Messages:
    95
    Likes Received:
    25
    any clues what i might be doing wrong-o?
     
  5. dor@tehexploa

    dor@tehexploa Registered Member

    Joined:
    Apr 25, 2009
    Messages:
    95
    Likes Received:
    25
    OK I figured out my problem.. The cookies were being saved in a file in a couple directories above the one in which the script was running. I cleared them and decided to do a random number in the x and y post fields.. The correct screen is now posting. w00t. This is all done for affiliate, but the affiliate isn't counting it as another action to be paid out. Any clue why?

    When I perform the same action in my browser the only thing I can discern that is different is the following:

    It continues to GET request a few more pages that Set Cookies but my script doesn't seem to go any further then the last POST.

    Also, I still haven't determined the X and Y values that are being sent in the original post.

    Someone PLEASE help me. :(
     
  6. dor@tehexploa

    dor@tehexploa Registered Member

    Joined:
    Apr 25, 2009
    Messages:
    95
    Likes Received:
    25
    I AM SO SORRY THAT I'VE NOW POSTED FOUR TIMES IN A ROW, BUT THESE HAVE ALL BEEN SHORT BUT WELCOME DEVELOPMENTS!

    I finallly figured this bastard out. Okay.. Lil' tip for the newer PHP cats out there. If you're cURLing a page. echo that page and ensure there isn't any hidden Javascript being performed... had me going for teh longest time..

    again i'm really sorry for all the posting, but i figured i should provide this tip to hopefully knock off a good ~4 hours of troubleshooting