loging in to a site with snoopy ( POST )

  • herbert noobkind

    i tried  with the function submit() to login to a site like http://www.kamikazegames.com/dominion/login.asp

    but i havent figured out yet how to do this
    help is greatly appreciated

    • Viktor Lieskovsky

      For this particular site, the logon will look like this:

      $ActionUrl = "http://www.kamikazegames.com/dominion/login2.asp?z=224102";
      $FormVars = array("Username" => "your_username_here", "Password" => "your_password_here");
      $snoopy = new Snoopy();
      $snoopy->submit($ActionUrl, $FormVars, array());

      More generaly, you can compose action urls using the private Snoopy method called _expandlinks, but with some limitations.

      I wrote this piece of code to get the proper action URL:
      // $action is the action specified in the form tag
      // $url is the URL of the form page
      // $ActionUrl is the resulting URL you can use to submit the form
      if ($action == "")
          $ActionUrl = $url;
      // snoopy incorrectly handles "/" (root) action links
      elseif (substr($action, 0, 1) == "/")
          preg_match("/^(http:\/\/)?([^\/]+)/i", $url, $matches);
          if ($matches[1] != "http://")
              $ActionUrl = "http://";
          $ActionUrl .= $matches[0].$action;
          $ActionUrl = $snoopy->_expandlinks($action, $url);

      There are still some improvements needed. Firstly, not to hardcode the 'http:// ' protocol to the links, instead look at the $url protocol and use it.


Log in to post a comment.

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

Sign up for the SourceForge newsletter:

No, thanks