INCLUDING JAVASCRIPT/HTML IN PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
arielpv1
Forum Newbie
Posts: 12
Joined: Mon Apr 21, 2008 7:57 pm

INCLUDING JAVASCRIPT/HTML IN PHP

Post by arielpv1 »

This is my short index.php site. It's a URL rotator.
It is http://www.mysite.com/index.php

Code: Select all

<?php
 
$version = "v1.01";
 
$linksfile ="urlrotator.txt";
 
$urls = file("$linksfile");
$url = rand(0, sizeof($urls)-1);
 
$goto = "$urls[$url]";
 
header("Location: $goto");
 
?>

urlrotator.txt contains: (http://www.mysite.com/page1.html and http://www.mysite.com/page2.html )

I want to add google analytics to http://www.mysite.com/index.php

I'm supposed to add the <script... JAVASCRIPT </script>... immediately before the </body> tag. That's what google analytics tells me. Where would I add that and how? is it possible?

Thanks!! :)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: INCLUDING JAVASCRIPT/HTML IN PHP

Post by Chris Corbyn »

There's no need to post the same message four times. I've removed all your duplicates.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: INCLUDING JAVASCRIPT/HTML IN PHP

Post by John Cartwright »

POSTING IN CAPS IS NOT COOL. :?
arielpv1
Forum Newbie
Posts: 12
Joined: Mon Apr 21, 2008 7:57 pm

Re: INCLUDING JAVASCRIPT/HTML IN PHP

Post by arielpv1 »

I'm sorry.
nowaydown1
Forum Contributor
Posts: 169
Joined: Sun Apr 27, 2008 1:22 am

Re: INCLUDING JAVASCRIPT/HTML IN PHP

Post by nowaydown1 »

Your index file doesn't appear to have any markup in it at all which complicates things a bit. Two things come to mind. I'm not sure how successful either of these will be for you. You could use try to using output buffering (php.net/ob_start) and just shove your script tag inline before your header redirect, or try to stick the script tag in both of your rotating files.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: INCLUDING JAVASCRIPT/HTML IN PHP

Post by RobertGonzalez »

Find the part of your app that displays the footer portion of your markup (wherever the closing body tag is) and include the analytics code there.

If there is more than one file that contains your footer markup then you may want to consider consolidating your markup into single files containing the unchanging portions.
Post Reply