SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Sep 2004
    Location
    seattle
    Posts
    306
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    using curl to login but it keeps trying to download

    hello,

    i found this script and modified to my needs, the problem is i tested it on my server and it works but when i upload it to the client's server it doesn't. it keeps trying to download the file instead of logging in and pulling content from a page

    Code:
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookie.txt");
    curl_setopt($ch, CURLOPT_URL,"http://site.com:81/login.php");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "username=user&password=pass");
    
    ob_start();      // prevent any output
    curl_exec ($ch); // execute the curl command
    ob_end_clean();  // stop preventing output
    
    curl_close ($ch);
    unset($ch);
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookie.txt");
    curl_setopt($ch, CURLOPT_URL,"http://sitewatch.com:81/index.php");
    
    $buf2 = curl_exec ($ch);
    
    curl_close ($ch);
    echo $buf2;
    the server it doesn't work on is running php 4.3.11 and curl version: libcurl/7.10.6 OpenSSL/0.9.7a ipv6 zlib/1.2.3

    and the server it does work on is running php 4.4.9 curl libcurl/7.19.0 OpenSSL/0.9.7a zlib/1.2.1.2 libidn/0.5.6

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Always turn up error reporting when debugging scripts.
    PHP Code:
    error_reporting(E_ALL);
    ini_set('display_errors'1); 

  3. #3
    SitePoint Addict
    Join Date
    Sep 2004
    Location
    seattle
    Posts
    306
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    followed your suggestion it still doesn't output any errors...just keeps try to download the file test.php until i click on the stop loading 'X' in firefox.

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Comment all the code out. gradually uncomment peices of it until you find the problem code.

    Make sure the server has php working. Make a phpinfo() script to test.

  5. #5
    SitePoint Addict
    Join Date
    Sep 2004
    Location
    seattle
    Posts
    306
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks i got it working


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •