curl-and-php
Login with PHP/cURL
Date: Tue, 02 Sep 2008 16:21:03 -0500
Hi, I'm trying to login to my school's website to get my schedule for
the day and I'm trying to do it all in PHP and cURL. First I hit the
login page to get the session cookie, then I post to the receiving page
of the login form with my credentials and then try to curl to my
schedule page. The problem occurs after logging in: I get sent to the
site's welcome page, thus leaving my script and I am unable to then go
to the schedule page. How can I stop this redirection and stop as soon
as I have the cookie that keeps me logged in so I can go to the schedule
page? My code is below:
<?php
$pages = array('home' =>
'https://my.school.ca/banprod/twbkwbis.P_WWWLogin',
'login' =>
'https://my.school.ca/banprod/twbkwbis.P_ValLogin',
'schedule' =>
'https://my.school.ca/banprod/bwskfshd.P_CrseSchd');
$ch = curl_init();
//Set options for curl session
$options = array(CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE
6.0; Windows NT 5.0)',
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_HEADER => TRUE,
//CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_COOKIEFILE => 'cookie.txt',
CURLOPT_COOKIEJAR => 'cookies.txt');
//Hit home page for session cookie
$options[CURLOPT_URL] = $pages['home'];
curl_setopt_array($ch, $options);
curl_exec($ch);
//Login
$options[CURLOPT_URL] = $pages['login'];
$options[CURLOPT_POST] = TRUE;
$options[CURLOPT_POSTFIELDS] = 'sid=xxxxxx&PIN=xxxxxx';
$options[CURLOPT_FOLLOWLOCATION] = FALSE;
curl_setopt_array($ch, $options);
curl_exec($ch);
//Hit schedule page
$options[CURLOPT_URL] = $pages['schedule'];
curl_setopt_array($ch, $options);
$schedule = curl_exec($ch);
//Output schedule
echo $schedule;
//Close curl session
curl_close($ch);
?>
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2008-09-02