title: Cannot enable cookie in php curl
body: <p>Here is my code to use curl:</p>
  
  <pre><code>class cURL {
      var $headers;
      var $user_agent;
      var $compression;
      var $cookie_file;
      var $proxy;
      var $process;
  
      function cURL($cookies = TRUE, $cookie = 'cookies.txt', $compression = 'gzip', $proxy = '') {
          $this-&gt;headers [] = 'Connection: Keep-Alive';
          $this-&gt;headers [] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
          $this-&gt;user_agent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)';
          $this-&gt;compression = $compression;
          $this-&gt;proxy = $proxy;      
  
          $this-&gt;cookies = $cookies;
          if ($this-&gt;cookies == TRUE)
              $this-&gt;cookie ( "c:/wamp/www/googlegroups/cookies/".$cookie );
  
          $this-&gt;process = curl_init ();
          curl_setopt ( $this-&gt;process, CURLOPT_HTTPHEADER, $this-&gt;headers );
          curl_setopt ( $this-&gt;process, CURLOPT_USERAGENT, $this-&gt;user_agent );
  
          if ($this-&gt;cookies == TRUE)
              curl_setopt ( $this-&gt;process, CURLOPT_COOKIEFILE, $this-&gt;cookie_file );
          if ($this-&gt;cookies == TRUE)
              curl_setopt ( $this-&gt;process, CURLOPT_COOKIEJAR, $this-&gt;cookie_file );
  
          curl_setopt ( $this-&gt;process, CURLOPT_ENCODING, $this-&gt;compression );
          curl_setopt ( $this-&gt;process, CURLOPT_TIMEOUT, 30 );
          if ($this-&gt;proxy)
              curl_setopt ( $this-&gt;process, CURLOPT_PROXY, $this-&gt;proxy );
          curl_setopt ( $this-&gt;process, CURLOPT_RETURNTRANSFER, 1 );
          curl_setopt ( $this-&gt;process, CURLOPT_FOLLOWLOCATION, 1 );
          curl_setopt ( $this-&gt;process, CURLOPT_SSL_VERIFYHOST, 0 );
          curl_setopt ( $this-&gt;process, CURLOPT_SSL_VERIFYPEER, 0 );
      }
  
      function __destruct(){
          curl_close ( $this-&gt;process );
          unlink($this-&gt;cookie_file);
      }
  
      function cookie($cookie_file) {
          if (file_exists ( $cookie_file )) {
              $this-&gt;cookie_file = $cookie_file;
          } else {
              if($fp = fopen ( $cookie_file, 'w' ))
              {
                  fclose($fp);
              }
              else $this-&gt;error ( 'The cookie file could not be opened. Make sure this directory has the correct permissions' );
              $this-&gt;cookie_file = $cookie_file;
          }
      }
      function get($url) {
          curl_setopt ( $this-&gt;process, CURLOPT_POST, 0);
          curl_setopt ( $this-&gt;process, CURLOPT_URL, $url);
          $return = curl_exec ( $this-&gt;process );
          return $return;
      }
  
   }
  
  $cc = new cURL();
  echo $cc-&gt;get("http://127.0.0.1/googlegroups/testcookie.php");
  </code></pre>
  
  <p>This is a very strange type of curl's malfunctioning that I've never experienced before.
  and this is the output of the testcookie.php : </p>
  
  <blockquote>
    <p>Cookies are NOT enabled on your
    browser</p>
  </blockquote>
  
  <p>Here is the funny thing if you remove unlink($this->cookie_file); from the destruction function the cookie file will not get deleted and next time you run this script you will get</p>
  
  <blockquote>
    <p>Cookies are enabled on your browser</p>
  </blockquote>
  
  <p>testcookie.php source code:</p>
  
  <pre><code>setcookie("test","test");
  if (isset ($_COOKIE['test']))
  {
      echo "Cookies are enabled on your browser";
  }
  else
  {
      echo "Cookies are &lt;b&gt;NOT&lt;/b&gt; enabled on your browser";
  }
  </code></pre>