Page 1 of 1
Google analytic for PHP Pages
Posted: Thu Sep 08, 2011 5:51 am
by macmachi
Hi,
I'm new to this forum and to the concept PHP as well.
I'm trying to use google analytic tracking code in my php site, but I don't know how to do so as I have worked with html pages all these days. The thing is, if I open the source page in any browser it shows <html> tags and other tags like head, title, keywords, body....but when I open through web server I can only see php files staring with <?php.....
Could any of you help me in implementing the analytic code in my pages created with PHP? Thank you so much!
Re: Google analytic for PHP Pages
Posted: Thu Sep 08, 2011 7:18 am
by Eric!
Your sever isn't configured correctly if you are seeing the <?php tags and the code. This means your server isn't recognizing your php and running it.
When the server is configured correctly the following file:
Code: Select all
<html>
<?php echo "<b>Hello World!</b>"; ?>
</html>
when viewed via your server with your browser will look like[text]<html>
<b>Hello World!</b>
</html>[/text]Talk to your service provider, or if you set it up, you'll need to fix the install for Apache or Microsoft because it isn't running.
Re: Google analytic for PHP Pages
Posted: Thu Sep 08, 2011 8:43 am
by macmachi
Hi Eric,
Thank you for your kind reply! I'm not familiar with PHP or accessing a server but only a little bit i know.
If the pages are not recognized how are all that pages in live online?
So, can I add <html> in all the pages that start with <?php..?
Could you please elaborate on how do I fix this up all by myself? Thanks for all your help! I appreciate it.
Eric! wrote:Your sever isn't configured correctly if you are seeing the <?php tags and the code. This means your server isn't recognizing your php and running it.
When the server is configured correctly the following file:
Code: Select all
<html>
<?php echo "<b>Hello World!</b>"; ?>
</html>
when viewed via your server with your browser will look like[text]<html>
<b>Hello World!</b>
</html>[/text]Talk to your service provider, or if you set it up, you'll need to fix the install for Apache or Microsoft because it isn't running.
Re: Google analytic for PHP Pages
Posted: Thu Sep 08, 2011 5:45 pm
by Jonah Bron
macmachi wrote:The thing is, if I open the source page in any browser it shows <html> tags and other tags like head, title, keywords, body....but when I open through web server I can only see php files staring with <?php.....
That's how PHP works, it's a server-side language. The server processes the PHP before sending it to the browser for display. The file doesn't need to start with <?php though: it just needs to surround any PHP code in the page. For example:
Code: Select all
<html>
<head>
<title><?php echo 'Blah blah' . $current_page; ?></title>
</head>
<body><?php
echo 'something <strong>else</strong>';
?>
</body>
</html>
Will come out like this (providing $current_page has been set to " foo"):
Code: Select all
<html>
<head>
<title>Blah blah foo</title>
</head>
<body>something <strong>else</strong>
</body>
</html>
Re: Google analytic for PHP Pages
Posted: Fri Sep 09, 2011 1:58 am
by macmachi
Thanks Jonah for letting me know of that.
Can you please show some light on my query?
I see all the pages open with <?php and ends with </html> where is the opening tag <html> ? I don't find the opening tag in any of the source files.
Secondly, where do I put the tracking code????? please help.
That's how PHP works, it's a server-side language. The server processes the PHP before sending it to the browser for display. The file doesn't need to start with <?php though: it just needs to surround any PHP code in the page. For example:
Code: Select all
<html>
<head>
<title><?php echo 'Blah blah' . $current_page; ?></title>
</head>
<body><?php
echo 'something <strong>else</strong>';
?>
</body>
</html>
Will come out like this (providing $current_page has been set to " foo"):
Code: Select all
<html>
<head>
<title>Blah blah foo</title>
</head>
<body>something <strong>else</strong>
</body>
</html>
[/quote]
Re: Google analytic for PHP Pages
Posted: Fri Sep 09, 2011 4:53 am
by macmachi
I solved the prob through a PHP developer we recently hired. Thank you Eric and Jonah for answering my question. Cheers!