thecard Posted August 28, 2008 Share Posted August 28, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/121707-how-does-the-google-ads-script-work/ Share on other sites More sharing options...
BlueSkyIS Posted August 28, 2008 Share Posted August 28, 2008 Javascript can talk to PHP directly via Ajax, or simply append parameters to a PHP script URL, e.g., window.open('somegooglescript.php?browser=IE&domain=whatever.com'), etc.... Quote Link to comment https://forums.phpfreaks.com/topic/121707-how-does-the-google-ads-script-work/#findComment-627818 Share on other sites More sharing options...
thecard Posted August 28, 2008 Author Share Posted August 28, 2008 I understand that, but if its ajax, how does it work across domains? Quote Link to comment https://forums.phpfreaks.com/topic/121707-how-does-the-google-ads-script-work/#findComment-627828 Share on other sites More sharing options...
thecard Posted August 28, 2008 Author Share Posted August 28, 2008 And just using the query strings...I'm not sure that would work. Quote Link to comment https://forums.phpfreaks.com/topic/121707-how-does-the-google-ads-script-work/#findComment-627858 Share on other sites More sharing options...
PHPTOM Posted August 28, 2008 Share Posted August 28, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/121707-how-does-the-google-ads-script-work/#findComment-627928 Share on other sites More sharing options...
thecard Posted August 28, 2008 Author Share Posted August 28, 2008 So how do you exactly make a php file look like a javascript file (using MOD_rewrite). So does the php get executed on the browser side? Quote Link to comment https://forums.phpfreaks.com/topic/121707-how-does-the-google-ads-script-work/#findComment-627956 Share on other sites More sharing options...
PHPTOM Posted August 28, 2008 Share Posted August 28, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/121707-how-does-the-google-ads-script-work/#findComment-627968 Share on other sites More sharing options...
BlueSkyIS Posted August 28, 2008 Share Posted August 28, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/121707-how-does-the-google-ads-script-work/#findComment-628004 Share on other sites More sharing options...
thecard Posted August 30, 2008 Author Share Posted August 30, 2008 Is there a way of doing this without using a spider? Quote Link to comment https://forums.phpfreaks.com/topic/121707-how-does-the-google-ads-script-work/#findComment-629645 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.