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.

How to Add PHP code in PHProxy

Discussion in 'PHP' started by CuteAbhi, Jan 3, 2009.

  1. #1
    Anybody please help me out :eek:...
    I am having admob advertise code with me I wanna use it into PHProxy but when I insert it gives Header already sent error.. Can any 1 guide me how to ad+ external PHP code into PHProxy I am attaching screenshot where I wanted to add code..



    [​IMG]
     
    CuteAbhi, Jan 3, 2009 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    What's the code? It's hard to know what header it's sending etc. Either way, headers must be sent before any output.

    Show me the code and I should be able to direct you.
     
    Danltn, Jan 3, 2009 IP
  3. sikka2010

    sikka2010 Well-Known Member

    Messages:
    1,578
    Likes Received:
    143
    Best Answers:
    0
    Trophy Points:
    175
    #3
    hmmmmmm writely said....................
     
    sikka2010, Jan 4, 2009 IP
  4. CuteAbhi

    CuteAbhi Guest

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Sure Attaching the code snap :cool:

    [​IMG]
     
    CuteAbhi, Jan 4, 2009 IP
  5. CuteAbhi

    CuteAbhi Guest

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Some of our advertisers have output
    echo mojiva_ad($mojiva_params);
    PHP:
    Let me know how do/where do I include this in line number 1145 above..
     
    CuteAbhi, Jan 4, 2009 IP
  6. CuteAbhi

    CuteAbhi Guest

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Please help me... how to do this :(
     
    CuteAbhi, Jan 5, 2009 IP
  7. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You have to do it after the last header info is se0nt.
    add the actual code to the post
     
    atlantaazfinest, Jan 5, 2009 IP
  8. CuteAbhi

    CuteAbhi Guest

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    code1:
    
    <?php
    /* editable area */
      $mob_mode = 'live'; // change mode from "test" to "live" when you are done testing
      $mob_alternate_link = ''; // use this to set a default link to appear if AdMob does not return an ad.
        
      /* end editable area */
        
      //used for ad targeting
      $mob_contents = '';
      $mob_ua = urlencode(getenv("HTTP_USER_AGENT"));
      $mob_ip = urlencode($_SERVER['REMOTE_ADDR']);
      
      $mob_m = '';
      if ($mob_mode=='test')
          $mob_m = "&m";
    
      $mob_url = 'http://ads.admob.com/ad_source.php?s=xxxxxxxxxx&u='.$mob_ua.'&i='.$mob_ip.$mob_m;
    
      @$mob_ad_serve = fopen($mob_url,'r');
    
      if ($mob_ad_serve) {
          while (!feof($mob_ad_serve))
              $mob_contents .= fread($mob_ad_serve,1024);
          fclose($mob_ad_serve);
      }
      $mob_link = explode("><",$mob_contents);
    
      $mob_ad_text = $mob_link[0];
      $mob_ad_link = $mob_link[1];
    
      if (isset($mob_ad_link) && ($mob_ad_link !='')) {
          //display AdMob Ad 
    echo '<a href="'. $mob_ad_link .'">'. $mob_ad_text . '</a>';
          
    }
      else {
          //no AdMob ad, display alternate
          echo $mob_alternate_link;
      }
    echo "<br/>\n";
    ?>
    
    PHP:
    Also this is Code2:

    
    <?php
    
    // change to "live" to disable demo mode and show real ads
    define("MOJIVA_MODE", "live");
    
    function mojiva_ad($mojiva_params = array())
    {
        // prepare url parameters of request
        $mojiva_get  = 'site='.urlencode('252');
        $mojiva_get .= '&ip='.urlencode($_SERVER['REMOTE_ADDR']);
        $mojiva_get .= '&ua='.urlencode($_SERVER['HTTP_USER_AGENT']);
        $mojiva_get .= '&url='.urlencode(sprintf("http%s://%s%s", (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == TRUE ? "s": ""), $_SERVER["HTTP_HOST"], $_SERVER["REQUEST_URI"]));
        $mojiva_get .= '&zone='.urlencode('277');
        $mojiva_get .= '&adstype=3'; // type of ads (1 - text only, 2 - images only, 3 - text + images)
        $mojiva_get .= '&key=1';
        $mojiva_get .= '&count=1'; // quantity of ads
        $mojiva_get .= '&keywords='; // keywords to search ad delimited by commas (not necessary)
        $mojiva_get .= '&whitelabel=0'; // filter by whitelabel(0 - all, 1 - only whitelabel, 2 - only non-whitelabel
        $mojiva_get .= '&premium=0'; // filter by premium status (0 - non-premium, 1 - premium only, 2 - both
        $mojiva_get .= '&paramBORDER='.urlencode('#000000'); // ads border color
        $mojiva_get .= '&paramHEADER='.urlencode('#cccccc'); // header color
        $mojiva_get .= '&paramBG='.urlencode('#eeeeee'); // background color
        $mojiva_get .= '&paramTEXT='.urlencode('#000000'); // text color
        $mojiva_get .= '&paramLINK='.urlencode('#ff0000'); // url color
        if(MOJIVA_MODE == "test") $mojiva_get .= '&test=1';
    
        // send request
        $mojiva_request = @fsockopen('ads.mojiva.com', 80, $errno, $errstr, 1);
        if ($mojiva_request) {
            stream_set_timeout($mojiva_request, 1000);
            fwrite($mojiva_request, "GET /ad?".$mojiva_get." HTTP/1.0\r\n");
            fwrite($mojiva_request, "Host: ads.mojiva.com\r\n");
            fwrite($mojiva_request, "Connection: Close\r\n\r\n");
            $mojiva_info = stream_get_meta_data($mojiva_request);
            $mojiva_timeout = $mojiva_info['timed_out'];
            $mojiva_contents = "";
            $mojiva_body = false;
            $mojiva_head = "";
            while (!feof($mojiva_request) && !$mojiva_timeout) {
                $mojiva_line = fgets($mojiva_request);
                if(!$mojiva_body && $mojiva_line == "\r\n") $mojiva_body = true;
                if(!$mojiva_body) $mojiva_head .= $mojiva_line;
                if($mojiva_body && !empty($mojiva_line)) $mojiva_contents .= $mojiva_line;
                $mojiva_info = stream_get_meta_data($mojiva_request);
                $mojiva_timeout = $mojiva_info['timed_out'];
            }
            fclose($mojiva_request);
            if (!preg_match('/^HTTP\/1\.\d 200 OK/', $mojiva_head)) $mojiva_timeout = true;
            if($mojiva_timeout) return "";
            return $mojiva_contents;
        }
    }
    
    ?>
    <?php
    
    // copy this snippet elsewhere on your page for display more of ads
    echo mojiva_ad($mojiva_params);
    echo '<br/>';
    
    PHP:
    Please Guide me regarding above 2 separate codes that what should I do if I don't want error Headers Already Sent in PHProxy..

    thx
     
    CuteAbhi, Jan 5, 2009 IP