Jump to content

Recommended Posts

I have been studying the google remote scripts for some time.

 

I know that the google ad script must:

 

1) Find out the domain name (easy in js).

 

2) Then select information from a database according the domain name.

 

3) Then output the information retrieved from the database.

 

But how does the script do this? Surely you would need a server side script to do this, not just a .js file!

 

agh!

Link to comment
https://forums.phpfreaks.com/topic/121707-how-does-the-google-ads-script-work/
Share on other sites

You call an external JS file. So then it just document.write's the ads? The external file isn't a JS file. It's a PHP file or another language but then dubbed via MOD_rewrite or something similar to be a .js.

 

It will have the header text/javascript I believe

PHP is executed server side as normal.

.htaccess:

RewriteEngine on
RewriteBase /
RewriteRule ^ads\.js$ ads.php

 

 

ads.php:

header('Content-type: application/javascript');
//You can do PHP stuff. But when you want to echo stuff do document.write
echo "document.write('hello world')";

 

 

Now you can do

<script type="text/javascript" src="ads.js" />

 

I don't know if this will actually work. But there is a chance

----------------

Now playing: 2pac - Changes

via FoxyTunes

to clarify, the way adsense ads works (at least the content ads): each ad has it's own identifier, included in the javascript. a special google spider (mediapartners) visits the page with the ad placed on it to collect keywords and determine the most relevant ads for your content. when the ad .js is executed, ads relevant to your content are served, based on the spider information. no magic involved. the domain name may have little or nothing at all to do with the ads served.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.