Drupal 4.6 ad sprinkling

I had been wondering how sites sprinkle ads in irregular parts of their index page. As it turns out, it's just a matter of a simple if statement I put at the end of my Drupal node.tpl.php template file.

  <?php if (!$page && ($seqid == 2 || $seqid == 6) && !preg_match("/^(132\.170|68\.2[0-2]{1}\d{1}|24\.\d{2,3}|70\.243|204\.210|209\.86)\.\d{1,3}\.\d{1,3}$/", $_SERVER['REMOTE_ADDR'])): ?>
  <div class="node_ad"><!--ad code here--></div>
  <?php endif; ?>

What does the preg_match do you ask? I don't think professors at school should see the ads on my site, since I do occasionally post assignments on my own site in addition to or instead of WebCT. The regex doesn't show the ads to the ucf.edu netblock or major local ISP address blocks.


» deekayen's blog · Delicious · Digg · Technorati Topics: · ·

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <hr /> <a> <p> <em> <strong> <cite> <code> <blockquote> <ul> <ol> <li> <dl> <dt> <dd> <div> <img> <h1> <h2> <h3> <h4> <h5>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options