title: https, Jquery, PHP, Curl and document.cookie
body: <p>First off what I am trying to do:
  I am trying to access a login page so that I can log in. The site is Https and requires cookies to be set so I am using jquery to run a PHP + Curl to get that page for me and store the cookies. Well I have been able to get the cookies but I keep getting a popup that Cookies are not set. So I looked at it a lot more and found that javascript does an initial check to see cookies are enabled:</p>
  
  <pre><code>function initLogin(){
  // check if cookie is enabled so applications can run
  if (document.cookie == "") {
  alert("Cookies are disabled. Cannot access mid-tier with this setting.\nPlease configure your browser to accept cookies.");
  return;
  } 
  ....Other Code... 
  }
  </code></pre>
  
  <p>I have looked through just about every post on this forum and tried a crap load of different code but no luck. So the question is how to get past this point? My understading is: Jquery calls the php script on the proxy/server and calls curl to get me the webpage. Curl will then save the cookies for later use but how do you use them. I thought just by setting them in a cookie file would be sufficient but I guess I was wrong. So I tired just setting them to CURLOPT_COOKIE but I dont know if this is correct.</p>
  
  <p>Here is a copy of the code that I am running:</p>
  
  <pre><code>function getpage(){
  $fullurl = "https://url/arsys/shared/login.jsp?/arsys/home";
  
  $ch = curl_init ();
  curl_setopt($ch, CURLOPT_HEADER, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_URL, $fullurl);
  $output = curl_exec ($ch);
  
  preg_match_all('|Set-Cookie: (.*);|U', $output, $results);    
  $newcookies = implode(';', $results[1]);
  echo "&lt;br&gt;COOKIES:" . $newcookies;
  curl_setopt ($ch, CURLOPT_COOKIE, $newcookies);
  echo curl_error($ch) . " " . $output;
  curl_close($ch);
  }
  </code></pre>
  
  <p>Output from above code:
  COOKIES:JSESSIONID=B4830242479D3DFD3235D17EE6A4DEB8;q=""HTTP/1.1 200 OK Cache-Control: no-cache Content-Type: text/html;charset=UTF-8 Server: Microsoft-IIS/7.5 Set-Cookie: JSESSIONID=B4830242479D3DFD3235D17EE6A4DEB8; Path=/arsys; Secure Set-Cookie: q=""; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/ Date: Fri, 20 Apr 2012 17:57:17 GMT Content-Length: 35657 </p>
  
  <p>I also tried:</p>
  
  <pre><code>function getpage(){
  $ckfile = "cookies/cookie.txt";
  $fullurl = "https://url/arsys/shared/login.jsp?/arsys/home";
  
  $ch = curl_init ();
  curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
  curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile);
  curl_setopt($ch, CURLOPT_HEADER, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_URL, $fullurl);
  $output = curl_exec ($ch);
  curl_close($ch);
  }
  </code></pre>
  
  <p>The cookies get saved in the correct file but still get the same message.</p>
  
  <p>I tried the code on google and it works fine its the javascript that is stopping me..</p>