Page 1 of 1

Login first then complete and submit form

Posted: Thu Dec 29, 2011 8:39 am
by scorpioserve
I am trying to create a script that will

• Login to an asp website
• Accept the cookie that site provides
• Complete the fields of a predefined form
• Submit that completed form

So that is the idea, here is the reason, my client deals with 4 websites that they submit career applications to everyday, this means that each time they have another client they need to login to 4 websites and submit 4 ever so slightly different forms on those sites. Sometimes they have 10 new clients a day, multiply that by 4 and yeah they take an entire day to do it all.
1 of these 4 websites is their own, and the other 3 they have to pay a monthly amount to so they can post their clients on them.

I would like a script or series of scripts that allows them to complete a single form on their own administration section of their website, their form will have all the same fields as the 3 websites combined. Once they complete the form I would like them to submit the form to their own website database. Upon successful submission I would like them to be presented with a page that has 3 buttons each clicked button submits to the respective website. Make sense?

Through some help and internet searching I have a script that allows me to complete a form and submit it. I have tested this on one of my other websites that I have created many many years ago, on a simple contact form, and that works great. Here is a copy of that script.

Code: Select all

function remote_method($url,$method,$var,$varc) { 
    if(is_array($var)&&is_array($varc)){ 
        if(count($var)==count($varc)){ 
            $keys=array(); 
            $vals=array(); 
            for($i=0;$i<=count($var)-1;$i++){ 
                array_push($keys,$var[$i]); 
                array_push($vals,$varc[$i]); 
            } 
            $params=array_combine($keys,$vals); 
        } 
        else{die('count for keys & values must be the same');} 
    } 
    else{$params=array($var=>$varc);} 
    $postdata=http_build_query($params); 
    $opts=array( 
        'http'=>array( 
            'method'=>$method, 
            'header'=> "Content-type: application/x-www-form-urlencoded\r\n".'Content-Length: '.strlen($postdata) . "\r\n", 
            'content'=>$postdata) 
        ); 
    $context=stream_context_create($opts); 
    $handle=fopen($url,'r',false,$context); 
    while(($buffer=fgets($handle,4096))!==false){$o.=$buffer;} 
    return $o; 
    fclose($handle); 
} 

//FORM FROM A TEST WEBSITE [url]http://www.homeimprovementguide.co.za/higuide_adv_sec.php?aid=5[/url]
echo remote_method("http://www.homeimprovementguide.co.za/scripts/comments_form.php","POST",array('comments_firstname','comments_email','comments_lastname','comments_company_name','comments_t  elephone','comments_description'),array('firstname','admin@example.com','surname','company name','012 345 6789','This is what the description area should say')); 
OK, that is where I am up to, I can make their website, their database, create the required administration section, create the required form, submit the form to their own database, create a 3 button landing page, and then I am stuck with making the above script login to the website first and accept the cookie on that website so I am allowed to run the remainder of the script that should successfully complete the form and submit it.

Can anyone help me figure out that part, apparently I should be using something called cURL to do what I want to do, but honestly I play hit and miss with php and do not know asp, I am more familiar with, AS3, html, css, and a little javascript.
So please try give step by step instructions where possible.