Banner Ad Placement

Hi.

Before we start, I know nothing about php/html apart from some very basic stuff so please bear with me.

Ok, I have a site and I wanted to have a banner ad in the top left of the screen. I have a banner ad program which generates the code to display and rotate the ads but it seems the only placement options are _top and that is where the banner goes, straight to the top of the page pushing everything else down.

Would anyone know how you place an ad in a specific position? Sorry if this seems a silly question but I am completely lost, the page ends in .php so I assume it is php. The script for the banner is javascript though.

Any help appreciated.

Alex
Jon20041Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Diablo84Commented:
Alex,

PHP will generate the output but the positioning will be handled client side by HTML/CSS and possibly JS.

Can you post the relevant code please...

Diablo84
geir_andersenSystems engineerCommented:
well, you could simply put this inside a <div> tag..  like this:
<div id="Layer1" style="position:absolute; left:14px; top:21px; width:165px; height:74px; z-index:1"><? include("ad-rotator.php"); ?></div>

This will place a layer 14 pixels from the left, 21 pixels from the top.
165 pixels wide and 74 pixels high.

Just figure out where you want the ad to show, and set the variables in the style="" section of the div...
NOTE!
I wrote this using PHP code to include the .php file rotating the ads.


-Geir
geir_andersenSystems engineerCommented:
Forgot to refresh..... again.
Sorry.

-Geir
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Jon20041Author Commented:
Hi,

This is all the code that is generated and is put in the <head> if that is the right place to put it, it is 127.0.0.1 as the site is running locally.

<script language='JavaScript' type='text/javascript' src='http://127.0.0.1/xxxxxxx/public_html/pages/banner/adx.js'></script>
<script language='JavaScript' type='text/javascript'>
<!--
   if (!document.phpAds_used) document.phpAds_used = ',';
   phpAds_random = new String (Math.random()); phpAds_random = phpAds_random.substring(2,11);

   document.write ("<" + "script language='JavaScript' type='text/javascript' src='");
   document.write ("http://127.0.0.1/xxxxxxx/public_html/pages/banner/adjs.php?n=" + phpAds_random);
   document.write ("&amp;clientid=2&amp;source=Test&amp;target=_blank");
   document.write ("&amp;exclude=" + document.phpAds_used);
   if (document.referrer)
      document.write ("&amp;referer=" + escape(document.referrer));
   document.write ("'><" + "/script>");
//-->
</script><noscript><a href='http://127.0.0.1/xxxxxxx/public_html/pages/banner/adclick.php?n=a12093a2' target='_top'><img src='http://127.0.0.1/xxxxxxx/public_html/pages/banner/adview.php?clientid=2&source=Test&n=a12093a2' border='0' alt=''></a></noscript>

Hope you can help.

Jon
Diablo84Commented:
The first line should be in the head section but the rest of it looks like it should go within the body tags where you want it to appear...  the output needs to be in the documents body, not the head section.

Judging by the code, the _top setting you metioned refers to the target (ie. the window the link will open in) rather then the position.

Diablo84
Jon20041Author Commented:
Ah ha, ok, so what method do I use to tell the banner where to go as it where?

Please bear with me on this one, I have been stranded with this page and I am not too sure what the best method is. I can generate the banner and rotate it and so on, I just don't know how to position it, The code is being entered into the header.php file so it only goes in the header. I am just not too sure how to position it within the header of the site.

Yes, I think you are correct about the _top bit, funnily enough it doesnt work at all when I put in _blank.

Would that div thing mentioned above work and if so how would I enter the code?

Thanks
Alex

PS : For anyone wondering who Jon is, that is my partner who pasted the code for me :)

Diablo84Commented:
You can contain it in a div but i would avoid absolute (or relative for that matter) positioning to be perfectly honest, for layout you should float the div's.

What do you currently have in header.php?

You would probably be looking at something similar to this:

-----------------------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script language='JavaScript' type='text/javascript' src='http://127.0.0.1/xxxxxxx/public_html/pages/banner/adx.js'></script>
</head>
<body>

<div style="width: 80%; margin: auto;">
<script language='JavaScript' type='text/javascript'>
<!--
   if (!document.phpAds_used) document.phpAds_used = ',';
   phpAds_random = new String (Math.random()); phpAds_random = phpAds_random.substring(2,11);

   document.write ("<" + "script language='JavaScript' type='text/javascript' src='");
   document.write ("http://127.0.0.1/xxxxxxx/public_html/pages/banner/adjs.php?n=" + phpAds_random);
   document.write ("&amp;clientid=2&amp;source=Test&amp;target=_blank");
   document.write ("&amp;exclude=" + document.phpAds_used);
   if (document.referrer)
      document.write ("&amp;referer=" + escape(document.referrer));
   document.write ("'><" + "/script>");
//-->
</script><noscript><a href='http://127.0.0.1/xxxxxxx/public_html/pages/banner/adclick.php?n=a12093a2' target='_top'><img src='http://127.0.0.1/xxxxxxx/public_html/pages/banner/adview.php?clientid=2&source=Test&n=a12093a2' border='0' alt=''></a></noscript>
</div>

</body>
</html>
-----------------------------------------------------------------------

Possibly without the closing body and html tags if this is an include file. It might be easier to modify the adjs.php and handle this completely with php.

Diablo84

Jon20041Author Commented:
<html>
<title></title>
<link href="<?=ApplicationConfiguration::getRootUrl()?>/css/main.css" rel="stylesheet" type="text/css">
<meta name="keywords" content="">

<head>
<script src="<?=ApplicationConfiguration::getRootUrl()?>/js/main.js"></script>
<script language='JavaScript' type='text/javascript' src='http://127.0.0.1/xxxxxxxxx/public_html/pages/banner/adx.js'></script>
<script language='JavaScript' type='text/javascript'>
<!--
   if (!document.phpAds_used) document.phpAds_used = ',';
   phpAds_random = new String (Math.random()); phpAds_random = phpAds_random.substring(2,11);

   document.write ("<" + "script language='JavaScript' type='text/javascript' src='");
   document.write ("http://127.0.0.1/xxxxxxxxx/public_html/pages/banner/adjs.php?n=" + phpAds_random);
   document.write ("&amp;clientid=2&amp;source=Test&amp;target=_blank");
   document.write ("&amp;exclude=" + document.phpAds_used);
   if (document.referrer)
      document.write ("&amp;referer=" + escape(document.referrer));
   document.write ("'><" + "/script>");
//-->
</script><noscript><a href='http://127.0.0.1/xxxxxxxxx/public_html/pages/banner/adclick.php?n=a12093a2' target='_top'><img src='http://127.0.0.1/xxxxxxxxx/public_html/pages/banner/adview.php?clientid=2&source=Test&n=a12093a2' border='0' alt=''></a></noscript>


</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
      <td colspan="2">
      <table width="100%" cellspacing="0" cellpadding="0" border="0">
      <td height="67" width="800" style="background-image: url('<?=ApplicationConfiguration::getRootUrl()?>/pics/header_bg.gif');">
            <table width="100%" cellspacing="0" cellpadding="0" border="0">
            <tr>
                  <td valign="top"><img src="<?=ApplicationConfiguration::getRootUrl()?>/pics/null.gif" height="0" width="324"/></td>
                  <td><img src="<?=ApplicationConfiguration::getRootUrl()?>/pics/header_title.gif"/></td>
            </tr>
            </table>
      </td>
      <td style="background-color:#E8EFF4;">&nbsp;</td>
      </td>
</tr>
<tr>
      <td colspan="2">
      <table width="100%" cellspacing="0" cellpadding="0" border="0">
      <tr>
            <td width="800"><img src="<?=ApplicationConfiguration::getRootUrl()?>/pics/topmenu_header.gif"/></td>
            <td style="background-image: url('<?=ApplicationConfiguration::getRootUrl()?>/pics/topmenu_right.gif')"><img src="<?=ApplicationConfiguration::getRootUrl()?>/pics/null.gif" height="1" width="1"/></td>
      </tr>
      </table>
      </td>
</tr>
<tr>
      <td colspan="2">
      <table width="100%" cellspacing="0" cellpadding="0" border="0">
      <tr>
            <td width="50" style="background-color:#90CEFA" valign="bottom"><img src="<?=ApplicationConfiguration::getRootUrl()?>/pics/topmenu_bottom_line.gif" height="1" width="100%"/></td>
            <td width="684" style="background-image:url('<?=ApplicationConfiguration::getRootUrl()?>/pics/topmenu_bg.gif')" height="17"></td>
            <td style="background-color:#91CEFA" valign="bottom"><img src="<?=ApplicationConfiguration::getRootUrl()?>/pics/topmenu_bottom_line.gif" height="1" width="100%"/></td>
      </tr>
      </table>
      </td>
</tr>
<tr>
      <td colspan="2">
            <table width="100%" cellspacing="0" cellpadding="0" border="0">
            <tr>
                  <td style="background-image: url('<?=ApplicationConfiguration::getRootUrl()?>/pics/topsubmenu_bg.gif')"><img src="<?=ApplicationConfiguration::getRootUrl()?>/pics/null.gif" width="100%" height="15"/></td>
            </tr>
            </table>
      </td>
</tr>
<tr>
      <td colspan="2">
            <table width="100%" cellspacing="0" cellpadding="0" border="0">
            <tr>
                  <td style="background-image: url('<?=ApplicationConfiguration::getRootUrl()?>/pics/topmenu_bottom.gif')"><img src="<?=ApplicationConfiguration::getRootUrl()?>/pics/null.gif" width="100%" height="5"/></td>
            </tr>
            </table>
      </td>
</tr>
</table>

That was the header.php file and here is the adjs.php file :-

<?php // $Revision: 2.1.2.9 $

/************************************************************************/
/* phpAdsNew 2                                                          */
/* ===========                                                          */
/*                                                                      */
/* Copyright (c) 2000-2005 by the phpAdsNew developers                  */
/* For more information visit: http://www.phpadsnew.com                 */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/



// Figure out our location
define ('phpAds_path', '.');


// Set invocation type
define ('phpAds_invocationType', 'adjs');



/*********************************************************/
/* Include required files                                */
/*********************************************************/

require      (phpAds_path."/config.inc.php");
require (phpAds_path."/libraries/lib-io.inc.php");
require (phpAds_path."/libraries/lib-db.inc.php");

if (($phpAds_config['log_adviews'] && !$phpAds_config['log_beacon']) || $phpAds_config['acl'])
{
      require (phpAds_path."/libraries/lib-remotehost.inc.php");
      
      if ($phpAds_config['log_adviews'] && !$phpAds_config['log_beacon'])
            require (phpAds_path."/libraries/lib-log.inc.php");
      
      if ($phpAds_config['acl'])
            require (phpAds_path."/libraries/lib-limitations.inc.php");
}

require      (phpAds_path."/libraries/lib-view-main.inc.php");
require (phpAds_path."/libraries/lib-cache.inc.php");



/*********************************************************/
/* Java-encodes text                                     */
/*********************************************************/

function enjavanate ($str, $limit = 0)
{
      $str   = str_replace("\r", '', $str);
      
      print "var phpadsbanner = '';\n\n";
      
      while (strlen($str) > 0)
      {
            if ($limit)
            {
                  $line = substr ($str, 0, $limit);
                  $str  = substr ($str, $limit);
            }
            else
            {
                  $line = $str;
                  $str  = '';
            }
            
            $line = addcslashes($line, "\0..\37'\\");
            $line = str_replace('<', "<'+'", $line);
            
            print "phpadsbanner += '$line';\n";
      }
      
      print "\ndocument.write(phpadsbanner);\n";
}



/*********************************************************/
/* Register input variables                              */
/*********************************************************/

phpAds_registerGlobal ('what', 'clientid', 'clientID', 'context',
                                 'target', 'source', 'withtext', 'withText',
                                 'exclude', 'block', 'referer', 'blockcampaign');



/*********************************************************/
/* Main code                                             */
/*********************************************************/

if (isset($clientID) && !isset($clientid))      $clientid = $clientID;
if (isset($withText) && !isset($withtext))  $withtext = $withText;

if (!isset($what))             $what = '';
if (!isset($clientid))       $clientid = 0;
if (!isset($target))       $target = '';
if (!isset($source))       $source = '';
if (!isset($withtext))       $withtext = '';
if (!isset($context))       $context = '';

if (isset($exclude) && $exclude != '')
{
      $exclude = explode (',', $exclude);
      $context = array();
      
      for ($i = 0; $i < count($exclude); $i++)
            if ($exclude[$i] != '')
                  $context[] = array ("!=" => $exclude[$i]);
}

// Set real referer
if (isset($referer) && $referer)
      $HTTP_REFERER = $HTTP_SERVER_VARS['HTTP_REFERER'] = stripslashes($referer);


// Get the banner
$output = view_raw ($what, $clientid, $target, $source, $withtext, $context);

// Show the banner
header("Content-type: application/x-javascript");
enjavanate($output['html']);

// Block this banner for next invocation
if (isset($block) && $block != '' && $block != '0' && $output['bannerid'])
      print ("\nif (document.phpAds_used) document.phpAds_used += 'bannerid:".$output['bannerid'].",';\n");

// Block this campaign for next invocation
if (isset($blockcampaign) && $blockcampaign != '' && $blockcampaign != '0' && $output['campaignid'])
      print ("\nif (document.phpAds_used) document.phpAds_used += 'campaignid:".$output['campaignid'].",';\n");

?>

Hope it means more to you than me!!

Alex
Diablo84Commented:
Given the code length and shared dependance on both JS and PHP, i don't think it is going to be practical to modify the script.

Unfortuently the use of tables for layout is going to make any adjustments to the design and layout that little bit more difficult. You will basically need the resulting output of the JS added to a table data cell (ie. within <td>and</td>) so this section of code:

<script language='JavaScript' type='text/javascript'>
<!--
   if (!document.phpAds_used) document.phpAds_used = ',';
   phpAds_random = new String (Math.random()); phpAds_random = phpAds_random.substring(2,11);

   document.write ("<" + "script language='JavaScript' type='text/javascript' src='");
   document.write ("http://127.0.0.1/xxxxxxxxx/public_html/pages/banner/adjs.php?n=" + phpAds_random);
   document.write ("&amp;clientid=2&amp;source=Test&amp;target=_blank");
   document.write ("&amp;exclude=" + document.phpAds_used);
   if (document.referrer)
      document.write ("&amp;referer=" + escape(document.referrer));
   document.write ("'><" + "/script>");
//-->
</script><noscript><a href='http://127.0.0.1/xxxxxxxxx/public_html/pages/banner/adclick.php?n=a12093a2' target='_top'><img src='http://127.0.0.1/xxxxxxxxx/public_html/pages/banner/adview.php?clientid=2&source=Test&n=a12093a2' border='0' alt=''></a></noscript>

Should be added:

...
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
     <td colspan="2">
     <table width="100%" cellspacing="0" cellpadding="0" border="0">
     <td height="67" width="800" style="background-image: url('<?=ApplicationConfiguration::getRootUrl()?>/pics/header_bg.gif');">
          <table width="100%" cellspacing="0" cellpadding="0" border="0">
          <tr>
               <td valign="top"><img src="<?=ApplicationConfiguration::getRootUrl()?>/pics/null.gif" height="0" width="324"/></td>
               <td>

--> HERE <--

<img src="<?=ApplicationConfiguration::getRootUrl()?>/pics/header_title.gif"/></td>
          </tr>
          </table>
     </td>
     <td style="background-color:#E8EFF4;">&nbsp;</td>
     </td>
</tr>
...

At some point i recommend that you pay a visit to the folks in the CSS topic area. They will be able to guide you towards creating a more practical layout which uses CSS and HTML divisions (<div>) rather then tables and nested tables. This would result in much shorter code in both length and file size, quicker and more efficient handling of the layout for the browser and syntax which is much cleaner and subsequently much easier to modify. This is not essential but it would make your life easier in the future should you need to make any changes.

Diablo84

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jon20041Author Commented:
Hi Diablo,

Many thanks, will try and get something sorted out.

Thanks for your time.

Alex
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Internet Marketing

From novice to tech pro — start learning today.