How to show ads at the top of all pages in a directory with 1000's of html pages ?

Discussion in 'Site & Server Administration' started by poseidon, Jan 26, 2007.

Thread Status:
Not open for further replies.
  1. #1
    Well, How can I show ads at the top of all pages in a directory with 1000's of html pages ? I don't want to manually add them.

    Can I do this with frames ? If yes, than How ? can this also be done using some kind of php code which gets added at the top of all the web pages in that directory ? the ads will be google adsense.
     
    poseidon, Jan 26, 2007 IP
  2. arnoldcr

    arnoldcr Peon

    Messages:
    125
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try to put all that pages in a template, i'm assuming is a static html website, if you are or will use php, you can use an "include" in the header
     
    arnoldcr, Jan 26, 2007 IP
  3. Lever

    Lever Deep Thought

    Messages:
    1,823
    Likes Received:
    94
    Best Answers:
    0
    Trophy Points:
    145
    #3
    You could do a global find & replace on a unique set of tags on the whole local site to insert the ads or, even better, a snippet of code for a server-side include.

    You can put SSIs in your pages even in html as long as your server is set up correctly to do so. It's been a while since I ran such a setup but I remember getting the IIS server I had to treat html as shtml pages.

    Going on from arnoldcr's recommendation of going php, you could maybe start to use phpadsnew in that SSI, which I have just found out has been re-launched/re-branded as Openads.
     
    Lever, Jan 26, 2007 IP
  4. poseidon

    poseidon Banned

    Messages:
    4,356
    Likes Received:
    246
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You meant including a header.php file ? Hmmm I am not sure that will be a very good solution for me as manually adding so many file is very difficult

    I was thinking about SSI but not sure how to use it ? should I talk to my host first ? any other option ? I am even fine with frames, if that's possible
     
    poseidon, Jan 26, 2007 IP
  5. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #5
    The following .NET function will add a specified HTML code after the <body> tag to every HTML file in a specified directory. It could be run on the server or locally, but I suggest a complete backup before using.

    
        Function addToAll(ByVal HTMLToInsert As String, ByVal DirOfFiles As String)
            Dim files() As String
            Dim fTxt As String
            Dim sr As StreamReader
            Dim sw As StreamWriter
    
            files = Directory.GetFiles(DirOfFiles, "*.html")
    
            For i = 0 To files.Length - 1
                'Read
                sr = New StreamReader(files(i))
                fTxt = sr.ReadToEnd
                sr.Close()
                sr = Nothing
                'Replace
                fTxt = Replace(fTxt, "<body>", "<body>" & HTMLToInsert)
                'Write
                sw = New StreamWriter(files(i), False)
                sw.WriteLine(fTxt)
                sw.Close()
                sw = Nothing
            Next
    
        End Function
    
    Code (markup):
    Take note that this will only do .html files not .htm (you can change what file types it edits by changing the *.html on line:
    files = Directory.GetFiles(DirOfFiles, "*.html")

    usage would be:
    addToAll("<a href='http://www.google.com'>Google</a>", "c:\dir1\")

    would add a link to google on the top of every HTML page in c:\dir1\...
    If you do not have visual studio to use this code it would have to be run using asp.net on the webserver.
     
    camjohnson95, Nov 5, 2008 IP
Thread Status:
Not open for further replies.