title: Php curl script working on localhost (xampp) but not when I upload it to hosting
body: <p>I know that similar questions have been asked but I think they are a little bit different or they have not solved my problem. First of all, I started to learn about PHP/curl and websites in general only a few weeks ago, so I am sure I am doing a lot of mistakes. For this reason, I would ask understanding from you.</p>
  
  <p>Okay, thanks to stackoverflow I have been able to "write" an script whose function is:</p>
  
  <ul>
  <li>Login to www.example.com/login.php</li>
  <li>"Fill a form" on www.example.com/submit.php?h=test</li>
  </ul>
  
  <p>The code is the following:</p>
  
  <p><strong>code.php</strong></p>
  
  <pre><code>&lt;?php
  
  error_reporting (E_ALL | E_STRICT);
  set_time_limit(0);
  
  function curl_login($url,$data,$proxy,$proxystatus){
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
      curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
      curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
      curl_setopt($ch, CURLOPT_URL, $url);
      ob_start();      // prevent any output
      $temp=curl_exec ($ch); // execute the curl command
      ob_end_clean();  // stop preventing output
  
  
  
      $fp = fopen("cookie.txt", "w");
      fclose($fp);
       $ch = curl_init();
      curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
      curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
      curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
      curl_setopt($ch, CURLOPT_TIMEOUT, 40);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_HEADER, TRUE);
      curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
      curl_setopt($ch, CURLOPT_POST, TRUE);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
      ob_start();      // prevent any output
      return curl_exec ($ch); // execute the curl command
      ob_end_clean();  // stop preventing output
      curl_close ($ch);
      unset($ch);    
  }                   
  
  $test1 = curl_login('http://www.example.com/login.php','username=itsme&amp;password=abcdedg&amp;login=Login','','off');
  
  
  function curl_submit($url,$data,$proxy,$proxystatus){
          $ch = curl_init();
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
      curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
      curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
      curl_setopt($ch, CURLOPT_URL, $url);
      ob_start();      // prevent any output
      $temp=curl_exec ($ch); // execute the curl command
      ob_end_clean();  // stop preventing output
      $fp = fopen("cookie.txt", "w");
      fclose($fp);
       $ch = curl_init();
      curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
      curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
      curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
      curl_setopt($ch, CURLOPT_TIMEOUT, 130);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_HEADER, TRUE);
      curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
      curl_setopt($ch, CURLOPT_POST, TRUE);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
      ob_start();      // prevent any output
      return curl_exec ($ch); // execute the curl command
      ob_end_clean();  // stop preventing output
      curl_close ($ch);
      unset($ch);
  }       
  
  $test2 = curl_submit('http://www.example.com/submit.php?h=test','url=www.heythere.com&amp;username=xyz&amp;submit=submit','','off');
  echo $test2;
  
  
  ?&gt;
  </code></pre>
  
  <p>The strange thing (for me) is that when I run it on Xampp everything works perfect, but when I run it from my hosting (in this example would be <a href="http://www.example.com/code.php" rel="nofollow">http://www.example.com/code.php</a>) it is not able to login and the header is: </p>
  
  <blockquote>
    <p>HTTP/1.1 301 Moved Permanently Date: Sat, 15 Aug 2015 10:50:26 GMT
    Server: Apache Expires: Mon, 26 Jul 1997 05:00:00 GMT Cache-Control:
    no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma:
    no-cache Set-Cookie: HEY=1342453645645645645; path=/ Last-Modified:
    Sat, 15 Aug 2015 10:50:26 GMT Location:
    <a href="http://www.example.com/login.php" rel="nofollow">http://www.example.com/login.php</a> Vary: Accept-Encoding,User-Agent
    Content-Length: 0 Content-Type: text/html HTTP/1.1 200 OK Date: Sat,
    15 Aug 2015 10:50:26 GMT Server: Apache Expires: Thu, 19 Nov 1981
    08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate,
    post-check=0, pre-check=0 Pragma: no-cache Last-Modified: Sat, 15 Aug
    2015 10:50:26 GMT Vary: Accept-Encoding,User-Agent Transfer-Encoding:
    chunked Content-Type: text/html</p>
  </blockquote>
  
  <p>I hope everything is clear and that you don't see so much mistakes!</p>