fetching a protected page

  • Anonymous - 2004-03-11

    I'm trying to use snoopy to fetch a page on a newspaper site so I can scan it for certain fields.  Problem is the page is password protected.  I have a userid and password (it's free to register) but I can't seem to get snoopy to retrieve the page.

    I've shortened my code to just the basics:

    1)  Fetch the page
    2)  If redirected to the signon screen, then post the userid/password

    Snoopy signs me on but instead of getting back the originally requested page, I get back a sign on successful page.

    3)  Re-fetch the original page

    I'm then directed again to the sign-on screen...and there lies my problem.  Any ideas?  Here's the basic code:

    $snoopy = new Snoopy;

    echo "START FIRST FETCH</br>";
    $filename = "http://www.ctnow.com/sports/college/husky/men/hc-ucmen0308.artmar08,1,4199149.story?coll=hc-headlines-ucmen-top";
    $filepass = "http://www.ctnow.com/services/site/premium/interceptlogin.register";

    echo "last address ".$snoopy->lastredirectaddr."\n";   
    if ($snoopy->lastredirectaddr) {
             echo "START SIGNON<br>";
            $formvars ["username"] = "billybob2243";
            $formvars ["password"] = "bobbilly";
            while(list($key,$val) = each($formvars)){
                                                    echo $key.": ".$val."<br>\n";
            $snoopy->submit($filepass,$formvars, array());
    echo $snoopy->results;

    • Denzo

      Denzo - 2004-03-31

      The code you've listed should work but why are you using setcookies()? This a private function and will be done automatically after you submit values. I haven't studied your example but the thing you'll probably need to do is after fetching that signon page taking the setcookies from the headers (use preg_match maybe) and keep them in a session if you your project is spreaded over multiple pages. Then when fetching the wanted page set the cookie vars in $snoopy->cookies. Good luck.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks