curl-and-php
HTTPS & cURL moving about https urls
Date: Thu, 21 Nov 2002 14:34:20 -0000
Hi, am very new to both PHP & cURL bit it looks excellent.
I am trying to log into a secure site and then move to another page and
add an item to a shopping basket as part of an automated procedure.
Log in is ok but when trying to then move to another https page I find
that I am rejected and need to log in again. I suspect its something to
do with the cookies not being passed. Any light would be greatly
appreciated.
Running latest php,curl,apache on win xp.
$cookie = "c:/directory/this_cookie.txt";
$data="";
$ch=curl_init('https://www.secure.asp');
if (!$ch){
die(sprintf('Error [%d]: %s',curl_errno($ch),curl_error($ch)));
}
$id="myid";
$pass="pass";
$submit="USERID=$id&password=$pass";
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$submit);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE
5.01; Windows NT 5.0)");
curl_setopt($ch,CURLOPT_HEADER,1);
$data=curl_exec($ch);
if (!$data){
die(sprintf('Error [%d]: %s',curl_errno($ch),curl_error($ch)));
}
curl_close($ch);
//echo $data;
//exit;
//////////////// if I drop out here I am logged in.
//unset($ch);
?>
<?php // second stage
$data="";
$ch=curl_init('https://www.secure/another_page.asp');
if (!$ch){
die(sprintf('Error [%d]: %s',curl_errno($ch),curl_error($ch)));
}
$quantity1=1;
$i=0;
$stuff[$i]="book-01";
$quantity1=1;
$submit=""
."Code1=".$stuff[$i]
."&quantity1=".$quantity1
."&Source=FastOrder&submit1.x=0&submit1.y=0"; // order to put in basket
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$submit);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie);
curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE
5.01; Windows NT 5.0)"); //
curl_setopt($ch,CURLOPT_HEADER,1);
$data=curl_exec($ch);
if (!$data){
die(sprintf('Error [%d]: %s',curl_errno($ch),curl_error($ch)));
}
curl_close($ch);
echo $data;
Thanks
*******************************************************
This message is intended for the stated addressee(s) only and may be
confidential. Access to this email by anyone else is unauthorised. Any
opinions expressed in this email do not necessarily reflect the opinions
of the Company. Any unauthorised disclosure, use or dissemination,
either whole or in part is prohibited. If you are not the intended
recipient of this message, please notify the sender immediately.
Please scan all attachments for viruses
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Received on 2002-11-21