Help with libcurl and forms please

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kireol
Forum Newbie
Posts: 3
Joined: Sun Oct 02, 2005 10:11 pm

Help with libcurl and forms please

Post by kireol »

Hi all,

I'm new to the dev network.

I'm trying to use libcurl to grab some pages from a website i think was wrote in ASP.

The web site is: http://madisonheightscity.is.bsasoftware.com

it's for public tax records.

Manually you'd click on "Tax Information Search" on the left. Then search on a street name like "alden" and that's it. It works fine when done manually!


The problems
I have my PHP script almost working. But I cant figure out what I'm doing wrong with these forms. I'm not sure if it's an ASP thing or what.


1) No matter what I set RadioButtonRecordCount for records per page to, it doesnt change.

2) I wrote a function to grab the "view state", but when I try to use this, it says invalid state.

PLEASE HELP!


Here's what I have for code so far:

Code: Select all

<?php
function getviewstate($result)
{
        $pattern = "/name=\"__VIEWSTATE\" value=\"[A-Z0-9+=\/]+/i";
        preg_match($pattern,$result, $matches);
        foreach ($matches as $match)
        {
        }
        $match = substr($match,26,strlen($match));
        return($match);
}

//start

$cookie_file_path = "cookies/cookiejar.txt"; // Please set your Cookie File path
$fp = fopen("$cookie_file_path","w") or die("<BR><B>Unable to open cookie file $mycookiefile for write!<BR>");
fclose($fp);
//sets city name
        $LOGINURL = "http://madisonheightscity.is.bsasoftware.com";
        $agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$LOGINURL);
        curl_setopt($ch, CURLOPT_USERAGENT, $agent);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
        curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
        $result = curl_exec ($ch);
        curl_close ($ch);

//goes to tax info page
        $LOGINURL = "https://is.bsasoftware.com/bsa.is/TaxServices/ServiceTaxSearch.aspx?i=3&appid=1";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$LOGINURL);
        curl_setopt($ch, CURLOPT_USERAGENT, $agent);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
        curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
        $result = curl_exec ($ch);
        curl_close ($ch);
        $viewstate = getviewstate($result);

//search form
        $LOGINURL = "https://is.bsasoftware.com/bsa.is/TaxServices/ServiceTaxSearch.aspx?i=3&appid=1";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$LOGINURL);
        curl_setopt($ch, CURLOPT_USERAGENT, $agent);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS,'RadioButtonRecordCount=35&TextBoxStreetName_sna=ann&__VIEWSTATE='.
                $viewstate);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
        curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
        $result = curl_exec ($ch);
        curl_close ($ch);
        $viewstate = getviewstate($result);
        print $result;
?>
Post Reply