Results 1 to 3 of 3

Thread: PHP fopen or cURL

  1. #1
    Join Date
    Apr 2005
    Location
    Haslemere, Surrey, UK
    Posts
    340
    Thanks
    5
    Thanked 3 Times in 3 Posts

    Default PHP fopen or cURL

    Hi All

    I am trying to implement a simple ad banner on a site and I have obtained code to add the banner ad to the page. Note that I am not a PHP guru at all.

    Question: I have the option of PHP code that uses fopen or cURL. Is their any particular one that doesnt work with RFH PHP? I have tried both sets of code and neither seem to work?

    If anyone can verify the code I would be very appreciative.

    many thanks

    Alastair

    fopen code
    PHP Code:
    if(!function_exists('banner_script'))
    {
    function 
    banner_script()
    {
    if(!isset(
    $_SERVER['REMOTE_ADDR'])) $server_ip '-';
    else 
    $server_ip urlencode($_SERVER['REMOTE_ADDR']);
    if(!isset(
    $_SERVER['SERVER_NAME'])) $server_name '-';
    else 
    $server_name urlencode($_SERVER['SERVER_NAME']);
    if(!isset(
    $_SERVER['REQUEST_URI'])) $uri '-';
    else 
    $uri urlencode($_SERVER['REQUEST_URI']);
    if(!isset(
    $_SERVER['HTTP_USER_AGENT'])) $ua '-';
    else 
    $ua urlencode($_SERVER['HTTP_USER_AGENT']);

        if(!
    $fp fopen('http://www.MyBannerAdDomain.com/adserver.php?pubid=10391&ip='.$server_ip.'&uri='.$server_name.$uri.'&ua='.$ua,'r')) echo ' ';
        else
        {
        echo 
    ' ';
             while(!
    feof($fp)) echo fgets($fp);
        
    fclose($fp);
        }
    }
    banner_script();

    cURL script
    PHP Code:
    if(!function_exists('banner_script'))
    {
    function 
    banner_script()
    {
    if(!isset(
    $_SERVER['REMOTE_ADDR'])) $server_ip '-';
    else 
    $server_ip urlencode($_SERVER['REMOTE_ADDR']);
    if(!isset(
    $_SERVER['SERVER_NAME'])) $server_name '-';
    else 
    $server_name urlencode($_SERVER['SERVER_NAME']);
    if(!isset(
    $_SERVER['REQUEST_URI'])) $uri '-';
    else 
    $uri urlencode($_SERVER['REQUEST_URI']);
    if(!isset(
    $_SERVER['HTTP_USER_AGENT'])) $ua '-';
    else 
    $ua urlencode($_SERVER['HTTP_USER_AGENT']);

    $ch curl_init('http://www.MyBannerAdDomain.com/adserver.php?pubid=10391&ip='.$server_ip.'&uri='.$server_name.$uri.'&ua='.$ua);
    curl_setopt($ch,CURLOPT_TIMEOUT,5);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
        if(!
    $ad curl_exec($ch)) RETURN ' ';
        else
        {
        
    $request curl_getinfo($ch);
            if(
    $request['http_code'] != 200) echo ' ';
            else echo 
    $ad;
        }
    curl_close($ch);
    }
    banner_script();

    Alastair - WOWD



  2. #2
    Join Date
    Feb 2004
    Posts
    4,903
    Thanks
    2
    Thanked 134 Times in 113 Posts

    Default

    Why dont either work, is there an error?
    Warren Ashcroft
    Red Fox UK Limited - Pioneers in Internet Technology
    http://www.redfoxuk.com
    w.ashcroft [at] redfoxuk.com

    NOTE: Forum Private Messaging should not be used to contact staff with support queries.

  3. #3
    Join Date
    Apr 2005
    Location
    Haslemere, Surrey, UK
    Posts
    340
    Thanks
    5
    Thanked 3 Times in 3 Posts

    Default

    Quote Originally Posted by Warren Ashcroft View Post
    Why dont either work, is there an error?
    It wasnt returning any info at all. However, I have just heard that the adserver is currently down.


    sorry to the knee jerk post.....
    Alastair - WOWD



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
  •