#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    300
    Rep Power
    1

    Question Error: Use of undefined constant RETURNTRANSFER


    Hi,

    Does anyone have a clue why I get the following error in my further following code ?

    Notice: Use of undefined constant RETURNTRANSFER - assumed 'RETURNTRANSFER' in C:\xampp\htdocs\test\curl.php on line 27

    Warning: curl_setopt() expects parameter 2 to be integer, string given in C:\xampp\htdocs\test\curl.php on line 27

    You are welcome to rectify the code where I'm goign wrong and then show me how it should have been.
    I actually, copied this from a youtube tutorial and they don;t get any errors but I do! Absurd! I copied it while I was learning the basics of cURL.

    Code:
    <?php 
    
    // Youtube Channel: Clever Techie; Video: PHP cURL Tutorial - Learn PHP Programming.
    
    // 1). Create cURL resource.
    $curl = curl_init();
    
    // 2). Set cURL options.
    curl_setopt($curl, CURLOPT_URL, 'http://www.google.com');
    
    // 3). Run cURL (execute http request).
    curl_exec($curl);
    
    // 4). Close cURL resource.
    curl_close($curl);
    
    
    // 1). $curl is going to be data type curl resource.
    $curl = curl_init();
    
    $search_string = "movies 2017";
    $url = "https://www.amazon.com/s/field-keywords=$search_string";
    
    // 2). Set cURL options.
    curl_setopt($curl, CURLOPT_URL, 'https://www.amazon.com');
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, RETURNTRANSFER, true);
    
    // 3). Run cURL (execute http request).
    $result = curl_exec($curl);
    preg_match_all("!https://images-na.ssl-images-amazon.com/images/I/[^\s]*?._AC_US_160_.jpg!, $result, $matches");
    
    //Use either one of the following 4 codes. (Use one by one in order to test and learn).
    
    //code 1:
    print_r($matches);
    
    //code 2:
    $images = array_unique($matches[0]);
    print_r($images);
    
    //code 3:
    $images = array_values(array_unique($matches[0]));
    print_r($images);
    
    //code 4:
    $images = array_values(array_unique($matches[0]));
    for ($i = 0; $i < count ($images); $i++) {
        echo "<div style='float:left; margin: 10 0 0 0; '>";
        echo "img src='$images[$i]'><br />";
    	echo "</div>";
    }
    
    // 4). Close cURL resource.
    curl_close($curl);
    
    ?>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,342
    Rep Power
    630
    Probably because RETURNTRANSFER is not defined. I suspect you really want to use CURLOPT_RETURNTRANSFER.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    300
    Rep Power
    1
    You are 100% CORRECT. 2 others suggested the same. Error gone now.

    Also, this line had the double quotes missing after the .jpg:

    preg_match_all("!https://images-na.ssl-images-amazon.com/images/I/[^\s]*?._AC_US160_.jpg!", $result, $matches);

    Thanks!
    Last edited by UniqueIdeaMan; May 12th, 2017 at 04:53 PM.
  6. #4
  7. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,804
    Rep Power
    4536
    Do you read the error messages you get? It literally tells you that it's an undefined constant. Even knowing nothing about what you're doing, if I search Google for "curl returntransfer" the first link shows me all of the valid constants I should be using in error messages.

    Show a little effort here, dude. Your missing quote should have been obvious in your text editor with highlighting or even if you used the PHP tags instead of CODE tags on here.
    -- Cigars, whiskey and wild, wild women. --
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    300
    Rep Power
    1
    Issue solved!
    Thread closed!

IMN logo majestic logo threadwatch logo seochat tools logo