cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Re: Login with PHP/cURL

From: Waruna Geekiyanage <warunans_at_gmail.com>
Date: Wed, 3 Sep 2008 09:18:04 +0530

setting CURLOPT_FOLLOWLOCATION to '0' should stop http header "Location"
redirects.
if you echo the output to the browser , it may be a javascript or http meta
redirect.

Waruna

On Wed, Sep 3, 2008 at 2:51 AM, Jeff Reznik <jeff_at_jeffreznik.com> wrote:

> 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'<https://my.school.ca/banprod/bwskfshd.P_CrseSchd%27>
> );
> $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
>

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2008-09-03