Search code examples
javascriptphpadsadvertisement-server

How do I generate Ad blocks with Javascript and PHP for my own Ad Network


I'm going to create an adserver by myself like google adsense. But I need to know few things to plan my project. I searched in many ways with google but I couldn't find clearly explained things that I need to know. I search in Stackoverflow but the results didn't explained me a much. So don't misunderstand this as a duplicate and don't misunderstand about me as I may not researched much(Because I tried it before post this).

This is a sample google ad code

<– Begin Google Adsense code –>
<script type=”text/javascript”>
google_ad_client = “ad-client-code-goes-here”;
google_ad_slot = “ad-slot-code-goes-here”;
google_ad_width = 300;
google_ad_height = 250;
</script>
<script type=”text/javascript”
src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”>
</script>
<– End Google Adsense code –>
  1. How do I generate ad codes like above, like google do ? (I mean just simple javascript codes to implement)

  2. How do I use javascript to serve ads when users use codes like above ?

  3. How do I connect php with javascript on this scenario ? I mean the source of the above code is just show_ads.js a javascript file. But I have to serve ads using php. (Because I don't think java will get ad details from database and create the ad content and send it without using php.) So how do I deal with that ?

(If anyone can provide simple javascript and php codes to explain this case I would be thankful. Because I need to know how these things done with codes in php and javascript)


Solution

  • First - Create a php file where you can generate advertise output based on google_ad_client, google_ad_slot, google_ad_width, google_ad_height (ex. showads.php) Second - call the php file through js.

    Example on js file:

    document.write('<iframe src="http://google.com/showads.php?google_ad_client='+ google_ad_client+'&google_ad_slot='+google_ad_slot+' margin=0 frameborder=0 scrolling=no allowtransparency=true ></iframe>');
    

    this is a simple example.

    but i will suggest to hire people if you want to create something like google adsense.