RE:Google Analitcs

Hi gang,

I'm new to PHP... as you will probably be able to easily recognize by my following dialog. ;-)

Anyway... I am taking over a website written in PHP with dreamweaver CS3.

It has a seperate footer.php file in a sub directory
and I believe this makes it a dynamic site? Am I wrong?

It appears Google provides two codes for google analytics tracking. Static and dynamic

http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55504

Utilizing the the dynamic code..... I get this error at the bottom of my pages.

Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/content/B/r/1/Hidden/html/-APPI-/NAV/footer.php on line 26


HELP.... :-(

Footer.php looks like this (located in a subdirectory)
************************
<?php

echo "
<br />
</td>
</tr>
<tr>
<td align=\"right\" ></td>
<td align=\"right\" valign=\"top\">
<table style=\"margin-left:15px;border-style:solid;border-width:2px;border-color:#000000\" width=\"580\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"336699\" height=\"20\" bordercolor=\"#000000\">
<tr>
<td>
<div align=\"center\"><font color=\"#FFFFFF\" face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">&copy;
Allied Power Products, Inc.</font></div>
</td>
</tr>
</table>
<div align=\"center\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\"><b><br>
CAUTION:</b> The final determination as to the suitability of<br>
this product for any purpose is solely that of the user.<br>
Our products are not to be used to lift or move<br>
people or to lift anything over people.</font></div>
</td>
</tr>
<?php
$virtual_page = "Main_Page"
include_once "analyticstracking.php" ?>"
</body>
</html>
";

?>


Analytics.php looks like this
************************
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>

<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-500580");
pageTracker._trackPageview('');
</script>
<?php
// End Analytics tracking code
?>

</body>
</html>

Line 26 is: $virtual_page = "Main_Page"

Actually, its not $virtual_page="Main_Page". Its because, You have opened the double quote and you are closing it at the end. (after </html>). And you are having a php tag within a php tag !

<?php

echo "
<br />
</td>
</tr>
<tr>
<td align=\"right\" ></td>
<td align=\"right\" valign=\"top\">
<table style=\"margin-left:15px;border-style:solid;border-width:2px;border-color:#000000\" width=\"580\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"336699\" height=\"20\" bordercolor=\"#000000\">
<tr>
<td>
<div align=\"center\"><font color=\"#FFFFFF\" face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">&copy;
Allied Power Products, Inc.</font></div>
</td>
</tr>
</table>
<div align=\"center\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\"><b><br>
CAUTION:</b> The final determination as to the suitability of<br>
this product for any purpose is solely that of the user.<br>
Our products are not to be used to lift or move<br>
people or to lift anything over people.</font></div>
</td>
</tr>";
<?php
$virtual_page = "Main_Page";
include_once "analyticstracking.php";
echo "</body>
</html>";
?>

This will probably do.

Thank you for your code. I inserted it in and... alas.... I still have an error. This time it at line 25....

Error on the bottom of all pages

Parse error: parse error, unexpected '?' in /home/content/B/r/1/Hidden/html/-APPI-/NAV/allied_footer.php on line 25

And what is in allied_footer.php ?

Dang. I did a stupid mistake.

<?php

echo "
<br />
</td>
</tr>
<tr>
<td align=\"right\" ></td>
<td align=\"right\" valign=\"top\">
<table style=\"margin-left:15px;border-style:solid;border-width:2px;border-color:#000000\" width=\"580\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"336699\" height=\"20\" bordercolor=\"#000000\">
<tr>
<td>
<div align=\"center\"><font color=\"#FFFFFF\" face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">&copy;
Allied Power Products, Inc.</font></div>
</td>
</tr>
</table>
<div align=\"center\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\"><b><br>
CAUTION:</b> The final determination as to the suitability of<br>
this product for any purpose is solely that of the user.<br>
Our products are not to be used to lift or move<br>
people or to lift anything over people.</font></div>
</td>
</tr>";
$virtual_page = "Main_Page";
include_once "analyticstracking.php";
echo "</body>
</html>";
?>

Check now.

I do appreciate your work.... Still seem to be getting this same funny error.

Parse error: parse error, unexpected '?' in /home/content/B/r/1/Hidden/html/-APPI-/NAV/allied_footer.php on line 25

FYI... allied_footer.php is the actual name of the footer file. I just referred to it as footer.php earlier to reduce confusion. I will stick with calling it allied_footer.php from now on.

Keep in mind, my "allied_footer.php" is in a sub directory. The analyticstracking.php is in the main directory. Let me know if this is an issue. Thank you!

Can you show us whats in allied_footer.php ? and yep, dont forget code tags.

Hi Nav,

I actually pasted your code, with nothing else, directly into allied_footer.php. So there is nothing but what you provided me at the moment.

I hope this is what you were asking??? I'm ready to provide info when you need it.... Thank you....:)

Okay! I checked what I had posted here and its working fine. Can you also post the code of analyticstracking.php ?

Here ya go... (FYI: I hid my tracking ID)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>

<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-******");
pageTracker._trackPageview('');
</script>
<?php
// End Analytics tracking code
?>

</body>
</html>

hmm.. I dont see anything wrong with this. What I dont understand is, how come your footer(allied_footer.php) starts off with no <html> tag, no <body tag, no <table> tag ! Are you sure this is all you have in allied_footer.php ? Are you sure you dont have any <? in between ?

Yep.... Perhaps you have found the issue???

Sounds like I need to add some lines of code at the top????

Well, yeah.. Add all the tags.. Search your code for "?". Check if its either <?php or ?>.

Hi Nav,

I did a little more research on the issue of allied_footer.php not having the information you believe is missing.

All of the example footer.php files I have seen on the net do not have any of that info.

The following is one of these examples where the footer file seems to rely on the header file, or index file for that stuff???

http://www.bobsmithphotography.net/a-little-php


Thank you for your help:confused:

FYT.... This is the error I have at the bottom of my pages with your latest code....

Parse error: parse error, unexpected T_INCLUDE_ONCE in /home/content/B/r/1/Hidden/html/-APPI-/NAV/allied_footer.php on line 26

Parse error: parse error, unexpected T_INCLUDE_ONCE in /home/content/B/r/1/Hidden/html/-APPI-/NAV/allied_footer.php on line 26

This usually comes from having a missing semicolon. The previous statement was never closed, so PHP isn't ready to begin a new statement - like require_once.

Check that lines 25 and 26 look like this (taken from the code pasted earlier)...

$virtual_page = "Main_Page";
include_once "analyticstracking.php";

If there's no missing semi-colon, then there shouldn't be a reason for that error.

As for the <html> tags, they shouldn't be in the footer.

Generally the way the templating system works is...

  • * Header.php - includes opening html tag, head tags, and opening body tag

  • * Page.php - includes the main content - everything inside the body tag

  • * Footer.php - includes the closing body and closing html tags, along with any footer info

In fact it seems rather strange that the analytics page (which you are including) contains all those tags. Since it's in the middle of an existing page, that might screw up the html.

- Walkere

How come the error keep changing from

Parse error: parse error, unexpected '?' in /home/content/B/r/1/Hidden/html/-APPI-/NAV/allied_footer.php on line 25

to

Parse error: parse error, unexpected T_INCLUDE_ONCE in /home/content/B/r/1/Hidden/html/-APPI-/NAV/allied_footer.php on line 26

? Comment the include_once line and check if you still get the error.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.