1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Search Engine Script question

Discussion in 'Products & Tools' started by scoyle74, Sep 10, 2004.

  1. #1
    Hello, first let me say that I think the search engine script is a great tool and I enjoy using it on my test and development servers.

    However, my problem lies in the fact that my ISP Host for our website has the allow_url_fopen setting turned off for 'security reasons'. Therefore I am unable to use the script as it is.

    Is there another function or option that I can use to modify the script to get it to work correctly? I have been informed that I might want to try using the curl function. Is that possible or am I SOL (sh*t out of luck).

    thanks,
    scoyle74 :confused:
     
    scoyle74, Sep 10, 2004 IP
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    You could use the curl function if it's enabled on your version of PHP. Although would require a few lines of coding, but it shouldn't be terribly difficult.
     
    digitalpoint, Sep 10, 2004 IP
  3. scoyle74

    scoyle74 Guest

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks, I was hoping it might be possible. I am fairly new to PHP and was wondering if someone could look at the code that I have modified. It is not working correctly, I keep getting curl_setopt and fget errors. I am probably missing the obvious in trying to change the code.

    If I don't use the feof and fget options and simply echo the curl_exec I get the results. It seems I might have to modify the way the results are returned as well but I am not sure.


    code:

    <?
    
    $ch = curl_init("http://search.digitalpoint.com/?q=");
    $fp = fopen("http://search.digitalpoint.com/?q=" . urlencode ($q) . "&key=" . urlencode ($key) . "&site=" . urlencode ($site) . "&start=" . min (990, $start), "r");
    
    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    
    $curl_exec = curl_exec($ch);
    
    while (!feof ($curl_exec) && $curl_exec) {
    		$line .= fgets ($curl_exec, 1024);
    	}
    curl_close($ch);
    
    fclose($fp);
    
    ?>
    PHP:
    Any help would be greatly appreciated.

    Scott
     
    scoyle74, Sep 13, 2004 IP
  4. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #4
    If you echo the $curl_exec variable does it show anything? Why are you using any of the stuff after the curl_exec line?
     
    digitalpoint, Sep 13, 2004 IP
  5. scoyle74

    scoyle74 Guest

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Sorry, I posted the incorrect code for you to look at.

    
    $url = "http://search.digitalpoint.com?q=";
    $ch = curl_init($url);
    $fp = fopen($url . urlencode ($q) . "&key=" . urlencode ($key) . "&site=" . urlencode ($site) . "&start=" . min (990, $start), "r");
    
    fpassthru ($fp);
    // that line makes cgi act like module
    
    //curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    
    $curl_exec = curl_exec($ch);
    
    //while (!feof ($curl_exec) && $curl_exec) { 
    //        $line .= fgets ($curl_exec, 1024); 
    //    }
    	
    //fclose($fp);
    curl_close($ch);
    
    echo "curl_exec: $curl_exec<br>";
    
    PHP:
    When I run the code, the results I get are
    When I uncomment the while loop to break up the results I get the fgets and feof errors.
     
    scoyle74, Sep 13, 2004 IP
  6. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #6
    Well looking at the PHP docs, it looks like you probably will want to set the CURLOPT_RETURNTRANSFER option, so you can return it to a variable.
     
    digitalpoint, Sep 13, 2004 IP
  7. scoyle74

    scoyle74 Guest

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Shawn, thanks for all the help. I got it to work, the code is below:

    
    $ch = curl_init("http://search.digitalpoint.com/?q=" . urlencode ($q) . "&key=" . urlencode ($key) . "&site=" . urlencode ($site) . "&start=" . min (990, $start));
    $fp = @fopen("http://search.digitalpoint.com/?q=" . urlencode ($q) . "&key=" . urlencode ($key) . "&site=" . urlencode ($site) . "&start=" . min (990, $start), "r");
    
    //fpassthru ($fp);
    // that line makes cgi act like module
    
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, $fp);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    
    $curl_exec = curl_exec($ch);
    
    while (!feof ($fp) && $fp) {
    		$line .= fgets ($fp, 1024);
    	}
    curl_close($ch);
    
    fclose($fp);
    
    PHP:
    Thanks again, for all your help.
    Scott :D
     
    scoyle74, Sep 14, 2004 IP