Hey guys,

I've hit a brick wall trying to login to an ssl site to update fields of a form and submit, mainly because(i'm guessing) it has a load of javascript within it and also a several redirects at and after login page. I have managed to come to the page after login and which lists my purchased domains, but when i make cURL fetch the dns manager link at this point it shows me the login page again. Basically im trying to update my A(IP Address) record for izzfx.com everytime my isp changes my ip address. this php script would run in bg with php-cli and evry 10 secs or so check my ip address through a website that returns your external ip address and if its different than the one that was previously recorded, auti login to dnsmanager and update values of A Address Record form and submit.

I was wondering if u guys could asist me in suggesting a different approach to this problem.

Thanks in advance, Izzy

Member Avatar for LastMitch

@Izzy Kiefer

I've hit a brick wall trying to login to an ssl site to update fields of a form and submit, mainly because(i'm guessing) it has a load of javascript within it and also a several redirects at and after login page. I have managed to come to the page after login and which lists my purchased domains, but when i make cURL fetch the dns manager link at this point it shows me the login page again. Basically im trying to update my A(IP Address) record for izzfx.com everytime my isp changes my ip address. this php script would run in bg with php-cli and evry 10 secs or so check my ip address through a website that returns your external ip address and if its different than the one that was previously recorded, auti login to dnsmanager and update values of A Address Record form and submit.

Can you post the code then explain the issue. It will be easier for everyone.

hey, sorry. here it is and the website with the current code is at http://izzfx.com/clientupdate if needed. it prints out 2 pages in 1 run. as u can see at the bottom it never proceeds forward as expected (by me of course).
first my index php has

index.php
//////////////////////////////////////
require_once 'core.class.php';
require_once 'ip.class.php';
require_once 'curl.class.php';

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

$i = new ip();
$c = new core();
$login = new curl('https://idp.securepaynet.net/login.aspx?ci=9106&prog_id=domains&spkey=SPSWNET-M1PWCORPWEB184'); // Initial Login page

// After Login, DNS Manager Link -- uses the same curl class created below(maybe this is th eproblem ????)
$login = new curl('https://dns.securepaynet.net/ZoneFile.aspx?identifier=5kypyvh9cmo7HVH1z0LAcUDSNawnxGrYkS0n4/8tfTMMGpeVG0LB198y5C67ogUEkwGQPSZB0iO+qqYAg3Pux28BoLv+OKRr4p86hjOWEy2TiS6VlzjSZokL63C8fzfs&sa=%2526prog_id%253ddomains');
///////////////////////////////////////////////////

curl.class.php
/////////////////////////////////////////////////////////////

class curl
{
    var $contentOfUrl;

    function curl($url)
    {
        echo $this->get_final_url($url, $timeout);
    }

    function get_final_url( $url, $timeout = 5 )
    {
        $ch = curl_init();

        ////////////////////////////////////////////////////
        curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1" );
        curl_setopt( $ch, CURLOPT_URL, $url );
        curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie );
        curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
        curl_setopt( $ch, CURLOPT_ENCODING, "" );
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
        curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
        curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
        curl_setopt( $ch, CURLOPT_TIMEOUT, $timeout );
        curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 );
        //////////////////////////////////////

        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

        curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
        curl_setopt($ch, CURLOPT_REFERER, 'https://dns.securepaynet.net/DNSSettings.aspx?zone=izzfx.com&zoneType=0&selectedTab=0&sa=%2526prog_id%253ddomains');

        curl_setopt($ch, CURLOPT_VERBOSE, 0);
        curl_setopt($ch, CURLOPT_HEADER, 0);

        curl_setopt ($ch, CURLOPT_POST, 1);
        curl_setopt ($ch, CURLOPT_POSTFIELDS, 'loginname=<My UserName>&password=<MyPassword>&validate=1&login_focus=false&pass_focus=false&Login=');

        curl_setopt ($ch, CURLOPT_COOKIEJAR, 'Ocookie.txt');

        $this->contentOfUrl = curl_exec ($ch); # This returns HTML

        $response = curl_getinfo( $ch );

        curl_close ($ch);

        echo $this->cleanElements($this->contentOfUrl);

        $this->craft_post_fields($array);
    }

    function craft_post_fields($array)
    {        

        preg_match('/<form name="Form1" [\w\W]*?<\/form>/', $this->contentOfUrl, $forms);
        //echo 'Before stripping '; 
        //print_r($forms);
        //echo 'After stripping '; 
        foreach ($forms as $f)
        {
            //echo $f;
        }

        //preg_match_all('/<input(.*?name="(.*?)".*?value="(.*?)")|(.*?value="(.*?)".*?name="(.*?)")/', $this->contentOfUrl, $formVars);
        //preg_match_all('/([\w]+=".*?")+?/', $this->contentOfUrl, $formInfo);


        //print_r($formVars);
        //print_r($formInfo);



    }

    //remove js,css,head.....
    function cleanElements($html)
    {

        $search = array (
           "'<script[^>]*?>.*?</script>'si",  //remove js
           "'<style[^>]*?>.*?</style>'si", //remove css 
           "'<head[^>]*?>.*?</head>'si", //remove head
           "'<link[^>]*?>.*?</link>'si", //remove link
           "'<object[^>]*?>.*?</object>'si"
                              ); 
                $replace = array ("", "", "", "", "");                 
        return preg_replace ($search, $replace, $html);
    }

////////////////////////////////////////////

thanx again

Member Avatar for LastMitch

@Izzy Kiefer

I've hit a brick wall trying to login to an ssl site to update fields of a form and submit, mainly because(i'm guessing) it has a load of javascript within it and also a several redirects at and after login page.

I think you missing something. I don't think you post the right file?

Since I feel you don't really know what I'm talking about here is a link of an example of CURL:

http://www.html-form-guide.com/php-form/php-form-submit.html

and this one is much suited for your situation if know where to used this code for your code:

http://semlabs.co.uk/journal/object-oriented-curl-class-with-multi-threading

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.