Results 1 to 3 of 3

 

Thread: Can anyone see why this doesnt work?

  1. #1
    Registered User

    Status
    Offline
    Join Date
    Sep 2003
    Posts
    315
    Thanks
    28
    Thanked 19 Times in 16 Posts


    I'm trying to download the Webgains discount codes feed programatically. It's generated in an odd way so it's hard to download using a script.

    http://www.webgains.com/newsletter/i...countCodes.csv

    I've tried Curl, fread, fgetcsv and copy to my server.

    Can anyone think of another solution?

    Thanks

    Example:

    <?php

    // Extract info from WebGains feed

    $webgainsVouchers = "http://www.webgains.com/newsletter/images/DiscountCodes.csv";

    unset($p);

    $ch = curl_init($webgainsVouchers);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $connection_timeout);
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);

    $p = curl_exec($ch);
    curl_close($ch);

    print($p);

    ?>

  2. #2
    Registered User

    Status
    Offline
    Join Date
    Mar 2007
    Posts
    11
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Hi,

    You need to authenticate your request with your username and password.

    eg

    <?php

    $webgainsVouchers = "https://www.webgains.com/newsletter/images/DiscountCodes.csv";

    $user = 'youruser';
    $password = 'yourpass';

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $webgainsVouchers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERPWD, $user . ":" . $password);

    $file = curl_exec($ch);
    curl_close($ch);

    print_r($file);

    ?>

    Hope that helps

    Tim

  3. #3
    scriptmonkey's Avatar
    Oranges & Lemons

    Status
    Offline
    Join Date
    Jan 2009
    Location
    Worthing
    Posts
    1,607
    Thanks
    112
    Thanked 253 Times in 192 Posts
    PHP Code:
    $url 'http://www.webgains.com/newsletter/images/DiscountCodes.csv';
    $filename 'codes.csv';
    $newfname $filename;

    $file fopen ($url"rb");
    if (
    $file) {
      
    $newf fopen ($newfname"wb");

      if (
    $newf)
      while(!
    feof($file)) {
        
    fwrite($newffread($file1024 ), 1024 );
      }
    }

    if (
    $file) {
      
    fclose($file);
    }

    if (
    $newf) {
      
    fclose($newf);

    That's what I use and it works fine.

    If you need to use cURL then change the request to https and add these to your options:

    PHP Code:
    curl_setopt($chCURLOPT_HTTPAUTHCURLAUTH_ANY);
    curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse); 
    The trouble with the rat race is that even if you win you're still a rat.
    Time passes. Listen. Time passes. Dylan Thomas
    Ebay Alerts to your inbox



Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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
  •  
To Top

Content Relevant URLs by vBSEO 3.5.0 RC2