<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi,<br>
<br>
The first think you need to do is automate the login, and store the
cookie used to keep you authed :<br>
<br>
To get the postcars, I use a ff plugin called 'Tamper Data'. <br>
I open it and login on the page I want, login, and grab the session
vars.<br>
Note any @ sign must be put back (they will be url encoded)<br>
<br>
These are from a class I wrote a while back to login to a supplier site
and pull their products.<br>
This is the main login post, and is flagged as done by the class var
_isLoggedIn (bool)<br>
<br>
$this->_chkfile is set in the constructor, to any file, mine is
/tmp/cookiejar<br>
<br>
public function Login() {<br>
$ckfile = $this->_chkfile;<br>
$postvars = "YOUR POST VARS HERE"<br>
$posturl = "THE URL THE LOGIN FORM POSTS TO"<br>
$ch = curl_init($posturl);<br>
curl_setopt ($ch, CURLOPT_REFERER, $posturl);<br>
curl_setopt ($ch, CURLOPT_URL, $posturl);<br>
$url = curl_setopt($ch, CURLOPT_POST, True);<br>
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);<br>
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, True);<br>
curl_setopt($ch, CURLOPT_HEADER, True); // DO NOT RETURN HTTP
HEADERS<br>
curl_setopt($ch, CURLOPT_HEADEROUT, False); // DO NOT RETURN
HTTP HEADERS<br>
curl_setopt($ch, CURLOPT_RETURNTRANSFER, True); // RETURN THE
CONTENTS OF THE CALL<br>
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);<br>
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);<br>
curl_setopt($ch, CURLOPT_COOKIESESSION, True);<br>
curl_setopt($ch, CURLOPT_VERBOSE, false); // switch on to see
what curl is up to.<br>
curl_setopt( $ch , CURLOPT_SSL_VERIFYPEER , false );<br>
curl_setopt( $ch , CURLOPT_SSL_VERIFYHOST , false );<br>
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible;
MSIE 5.01; Windows NT 5.0)');<br>
$data = curl_exec($ch);<br>
if ($data == false){<br>
die('Could not save/logon');<br>
}<br>
curl_close($ch);<br>
// add code to test if this was in fact true.<br>
$this->_isLoggedIn = True;<br>
return $data;<br>
}<br>
<br>
Then I have the send with cookie routine, that calls any further urls
with the cookie, and also logs in if I was not<br>
<br>
public function sendWithCookie($url) {<br>
if ($this->_isLoggedIn == False) {<br>
$this->Login();<br>
}<br>
$ckfile = $this->_chkfile;<br>
$ch = curl_init($url);<br>
curl_setopt ($ch, CURLOPT_URL, $url);<br>
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);<br>
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);<br>
curl_setopt($ch, CURLOPT_VERBOSE, false);<br>
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible;
MSIE 5.01; Windows NT 5.0)');<br>
curl_setopt( $ch , CURLOPT_SSL_VERIFYPEER , false );<br>
curl_setopt( $ch , CURLOPT_SSL_VERIFYHOST , false );<br>
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);<br>
$data = curl_exec($ch);<br>
if (empty($data)){<br>
$this->_isLoggedIn == False;<br>
die('Send with cookie failed');<br>
}<br>
curl_close($ch);<br>
return $data;<br>
}<br>
<br>
On some site, I have found that you must first load teh homepage, so
their internal 'can you use cookies' stuff is setup.<br>
<br>
public function loadhomepageCookies($url){<br>
$ckfile = $this->_chkfile;<br>
$ch = curl_init($url);<br>
curl_setopt ($ch, CURLOPT_URL, $url);<br>
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, True);<br>
curl_setopt($ch, CURLOPT_HEADER, True); // DO NOT RETURN HTTP
HEADERS<br>
curl_setopt($ch, CURLOPT_HEADEROUT, False); // DO NOT RETURN
HTTP HEADERS<br>
curl_setopt($ch, CURLOPT_RETURNTRANSFER, True); // RETURN THE
CONTENTS OF THE CALL<br>
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);<br>
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);<br>
curl_setopt($ch, CURLOPT_COOKIESESSION, True);<br>
curl_setopt($ch, CURLOPT_VERBOSE, false);<br>
curl_setopt( $ch , CURLOPT_SSL_VERIFYPEER , false );<br>
curl_setopt( $ch , CURLOPT_SSL_VERIFYHOST , false );<br>
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible;
MSIE 5.01; Windows NT 5.0)');<br>
$data = curl_exec($ch);<br>
curl_close($ch);<br>
}<br>
<br>
Hope this helps you get on track<br>
<br>
-Lucas<br>
<br>
On 01/12/10 13:45, Shanon Loughton wrote:
<blockquote
cite="mid:AANLkTinUynPOKgp30dP7uvuVXGFgZzi8wxvsPqSOoQ5Y@mail.gmail.com"
type="cite">Hi all<br>
<br>
Im trying to extract our monthly telstra bill from the hideous portal <a
moz-do-not-send="true"
href="https://www.telstrabusiness.com/business/login.jsp">https://www.telstrabusiness.com/business/login.jsp</a><br>
And I know the manual sequence with POST data and URLs except I cant
seem automate it with Ubuntu, Apache, PHP & cURL, specifically
logging in.<br>
<br>
If anyone can help that would be appreciated?<br>
<br>
thanks<br>
Shanon<br>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
PLUG discussion list: <a class="moz-txt-link-abbreviated" href="mailto:plug@plug.org.au">plug@plug.org.au</a>
<a class="moz-txt-link-freetext" href="http://www.plug.org.au/mailman/listinfo/plug">http://www.plug.org.au/mailman/listinfo/plug</a>
Committee e-mail: <a class="moz-txt-link-abbreviated" href="mailto:committee@plug.linux.org.au">committee@plug.linux.org.au</a>
</pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">--
Regards
Lucas van Staden
<a class="moz-txt-link-freetext" href="http://www.proxiblue.com.au/">http://www.proxiblue.com.au/</a> (Consumer Electronics Retail Shop)
<a class="moz-txt-link-freetext" href="http://www.vanstaden.com.au/">http://www.vanstaden.com.au/</a> (Linux)
</pre>
</body>
</html>