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

curl-and-php

Re: Login with PHP/cURL

From: Jeff Reznik <jeff_at_jeffreznik.com>
Date: Tue, 02 Sep 2008 23:38:32 -0500

I did have that option set to false, so I ruled out it being a Location
redirect. Rather than echoing it out to the browser I wrote it to a
file and found that it was an http meta redirect. This redirect can be
avoided by setting CURLOPT_RETURNTRANSFER to TRUE and either not echoing
the output at all or filtering out the page first. Thank you for your
help, I am understanding cURL a lot more now.

Waruna Geekiyanage wrote:
> 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
> <mailto: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
>
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2008-09-03