global static variable to be accessed in comment.tpl.php, node.tpl.php and in page.tpl.php I wanted to show some ads inside the content (node, comments) and body.
I decided to add them using the template by adding some lines to comment.tpl.php, node.tpl.php and page.tpl.php

for example in comment.tpl.php I have:

print render($content);
if($id%3 == 1){
  echo "&lt;iframe width='720' height='80' src='#####'&gt;&lt;/iframe&gt;";
}


I think this is a good way of adding ads

Now that the ad code is repeated in these 3 files, I want to use a Global static variable so that the ad code can be placed in one place and can be access from these 3 tpl.php files

Can somebody please point me how to do it? Or an alternative Method of achieving it?
You can use preprocess functions to add template variables in Drupal.

For example, you could use a generic preprocess function like

hook_preprocess

And add your variable there.

It will then be available in all the other template files.