Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

login via mechanize major headache

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
hi,

I'm trying to automate a login into one of our ancillary business partners.

their system is PHP and it seems they use a session cookie to validate the form being submitted.

I've tried to use the following code
Code:
use [URL unfurl="true"]WWW::Mechanize;[/URL]   
use HTTP::Cookies;

my $URL = "[URL unfurl="true"]https://$myurl/login.php";[/URL]

my $mech = [URL unfurl="true"]WWW::Mechanize->new();[/URL]

$mech->agent_alias( 'Windows IE 6' );
$mech->cookie_jar(HTTP::Cookies->new());
$mech->get( $URL );
$mech->form_name( 'login' );
$mech->field( username => uc($user) );
$mech->field( password => $Pword );
$mech->click();
my $lnk = $mech->uri;
print "Location: $lnk\n\n";
exit();

Now i've dome some checking and printing to the screen and eveything works in terms of the mechanize loging in, however, when I then re-route the browser to the members area section, the browser displays the login page.

I'm assuming that the HTTP:Cookies , isn't actualy creating any of the cookies from the mechanize to the actual PC 'IE' cookies cache and so sees the attempt to go to the members area as invalid as the client doesn't seem to contain the session cookie.

Is there a way round this?

how can I automate a login to a website aquiring the required cookies for the session and login them in?

I really appreciate any input on this one!



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
It's ok, i didn't solve the mechanize problem, but found another method to login automatically.

Cheers, 1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
I used a form with the required fields, prepopulated them and auto submitted the form with JS.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top