No Ads Script?

Started on the old forum in May 2008 · view the original in the archive · old links redirect here

5 replies · 659 views · started 18 years ago · 1 min read

5 participants
hypetype Developer · 128 posts #1

what if ur running ads on ur site, and now site is live, how can i make a coding that if no site is running i can have my own random links on my site?

FOR EXAMPLE, THE ADMOB CODING:

<?php

  /* editable area */
  $mob_mode = 'test'; // 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=a147e97a3ca3d3a&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 '[url="'. $mob_ad_link .'"]'. $mob_ad_text . '[/url]';
  }
  else {
      //no AdMob ad, display alternate
      echo $mob_alternate_link;
  }
?>
hypetype Developer · 128 posts #2

i did somethin like this where is bold, but get errors, like when ads are running, my ads also display, can any1 help me

<?php /* editable area */ $mob_mode = 'test'; // change mode from "test" to "live" when you are done testing $mob_alternate_link = **echo myads()**; // 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=a147e97a3ca3d3a&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 ''. $mob_ad_text . ''; } else { //no AdMob ad, display alternate echo $mob_alternate_link; } ?>
wizard Senior · 493 posts #3

create a table for your own ads fields id, adurl, adlink

the do this

$chk = mysql_fetch_array(mysql_query("SELECT adurl, adlink FROM ads ORDER BY RAND() LIMIT 0,1"));

$mob_alternate_link = '[url="'.$chk[0].'"]'.$chk[1].'[/url]';
andre3 Developer · 192 posts #4

do it like this mate... first call the function on the page that u want the ads to show admob(); ,then check to see if the admob ads is empty...

admob function///////////////////

function admobads{
  /* editable area */
  $mob_mode = 'test'; // 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=a147e97a3ca3d3a&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 '[url="'. $mob_ad_link .'"]'. $mob_ad_text . '[/url]';
  }
  else {
      //no AdMob ad, display alternate
     ///// echo $mob_alternate_link;
  }

}

/////////////////put this on the page where u want the ads to show

$admob = admobads();

if($admob==""){

echo myads();

}else {

echo "<a href=\"$mob_ad_link\"> $mob_ad_text </a>";

}
WhiteWarrior Principal · 1,419 posts #5

Thats a good way but Wizards way is simple and is not much coding todo

moviestar Newbie · 1 posts #6

This code will work, used it loads of times with diffrent ad networks etc

$random_url = array("http://url", "http://url", "http://url", "http://url", "http://url", "http://url");

$url_title = array("my site", "my Sites", "my Sites", "my sites text", "my sites", "myads bla bla");

srand(time()); $random = (rand()%6); print("

<a href="$random_url[$random]">$url_title[$random]</a> ");

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close