A typical browser based user visits site (A), then links to some sub page (B), then another (C), and lastly reviews their activity on page (D)
I’m trying to simulate these first steps via curl so that upon firing my script, it interacts with the target domain, and the user ends up on (D) without needing to take the intermediary actions.
I don’t have much experience with curl, and I have a feeling that I’m botching something at the end when I go to that final page (cookies that I’d explicitly set are overwritten, etc). I also remain on the URL of my script rather than really being on that other site…but if I use a Location header, I’m even more certainly ignoring the prior actions.
What I get from the below is I end up on (D) with no recognition of having previously hit (A)(B)(C)
This is the code I’ve been trying to work with, but I’m not sure whether I’m missing some CURLOPT, or if it’s something more fundamental in my approach. Thanks for any guidance.
<?php
$item1=990525;
$item2=208208;
$home="http://www.somedomain.com";
$add=$home."/cart/addSkuByButton.do;jsessionid=0000RSqxtdShvtVm0lVAb29p-9N:1659q38ci?ajaxATCRequest=true&sourcePage=&cmd_addCart.button.INDEX[0]=Add%20to%20Cart&trackingCategory=1000000000&entryFormList[0].selected=on&entryFormList[0].sku=";
$toCart="&entryFormList[0].qty=";
$cart=$home."/cart/shoppingCart.do;jsessionid=0000RSqxtdShvtVm0lVAb29p-9N:1659q38ci";
session_start(); //do I need this?
//setup
$c=curl_init();
curl_setopt($c,CURLOPT_RETURNTRANSFER,true);
curl_setopt($c,CURLOPT_COOKIESESSION,true); //should I use this? I've also tried COOKIEFILE without success
curl_setopt($c,CURLOPT_FOLLOWLOCATION, true);
curl_setopt($c,CURLOPT_HEADER, 1);
//set a session ID
curl_setopt($c,CURLOPT_COOKIE, "jsessionid=0000RSqxtdShvtVm0lVAb29p-9N:1659q38ci; path=/; domain=www.somedomain.com");
//visit main domain
curl_setopt($c,CURLOPT_URL, $home);
curl_exec($c);
//programattically visit sub pages
curl_setopt($c,CURLOPT_URL, $add.$item1.$toCart);
curl_exec($c);
curl_setopt($c,CURLOPT_URL, $add.$item2.$toCart);
curl_exec($c);
curl_setopt($c, CURLOPT_RETURNTRANSFER, false);
curl_setopt($c,CURLOPT_HEADER, false);
//actually visit final page
curl_setopt($c,CURLOPT_URL, $cart);
curl_exec($c);
curl_close($c);
?>
curl won’t execute any javascript, which I am guessing is your problem. When a browser based user visits a site, the javascript is executed by the browsers javascript interpreter. curl will simply return the plain text source code.
Does the curl library execute javascript inside pages?