Welcome to WebmasterWorld Guest from 54.145.222.231

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Yet another question about PHP Includes

Social buttons and browser testing right within the include file

   
3:12 pm on Aug 14, 2012 (gmt 0)

5+ Year Member



HI gents,

Here is what I got a bit stack with, I have an include file lets name it includes/social.php with following content:

<!--=================== social buttons ==================-->
<div id="social">
<!-- Google +1 button -->
<div style="float:right;padding-top:1px;">
<script type="text/javascript">document.write('<div class="g-plusone" data-size="tall"><\/div>');</script>
<script type="text/javascript">
(function() {
var z = document.createElement('script'), s = document.getElementsByTagName('script')[0];
z.type = 'text/javascript';
z.async = true;
z.src = 'https://apis.google.com/js/plusone.js';
s.parentNode.insertBefore(z, s);
})();
</script>
</div>
<!-- End Google +1 button -->

<!-- Facebook button -->
<div style="float:right;padding-right:2px;">
<script type="text/javascript">
//<![CDATA[
document.write('<div id="fb-root"><\/div><fb:like href="<?php echo $url;?>" send="false" layout="box_count" width="35" show_faces="false" font="arial"><\/fb:like>');
(function() {
var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
s.type = 'text/javascript';
s.async = true;
s.src = 'http://connect.facebook.net/en_US/all.js#xfbml=1';
s1.parentNode.insertBefore(s, s1);
})();
//]]>
</script>
</div>
<!-- End Facebook button -->

<!-- Tweet Button -->
<div style="float:right; margin-right:11px;">
<a href="http://twitter.com/share?via=youraccount&amp;count=vertical" class="twitter-share-button">Tweet</a>
<script type="text/javascript">
var a = document.createElement('script'), b = document.getElementsByTagName('script')[0];
a.type = 'text/javascript';
a.async = true;
a.src = 'http://platform.twitter.com/widgets.js';
b.parentNode.insertBefore(a,b);
</script>
</div>
<!-- End Tweet Button -->
<!-- end #social --></div>
<!--=================== end.social buttons ==================-->


and basically using this on every page of my site like below:

<?php 
if (!empty($_SERVER['HTTP_USER_AGENT']))
{
$isFirefox = (strpos($_SERVER['HTTP_USER_AGENT'],"Firefox") !== false);
} else {
$isFirefox = false;
}
if ($isFirefox) { echo ' '; }
else
include("/includes/social_buttons.php");?>


Right, so there is no problem with this it works just fine, but what I would like to do is the following:

if (!empty($_SERVER['HTTP_USER_AGENT']))
{
$isFirefox = (strpos($_SERVER['HTTP_USER_AGENT'],"Firefox") !== false);
} else {
$isFirefox = false;
}
if ($isFirefox) { echo ' '; }
else
include("
<!--=================== social buttons ==================-->
<div id="social">
<!-- Google +1 button -->
<div style="float:right;padding-top:1px;">
<script type="text/javascript">document.write('<div class="g-plusone" data-size="tall"><\/div>');</script>
<script type="text/javascript">
(function() {
var z = document.createElement('script'), s = document.getElementsByTagName('script')[0];
z.type = 'text/javascript';
z.async = true;
z.src = 'https://apis.google.com/js/plusone.js';
s.parentNode.insertBefore(z, s);
})();
</script>
</div>
<!-- End Google +1 button -->

<!-- Facebook button -->
<div style="float:right;padding-right:2px;">
<script type="text/javascript">
//<![CDATA[
document.write('<div id="fb-root"><\/div><fb:like href="<?php echo $url;?>" send="false" layout="box_count" width="35" show_faces="false" font="arial"><\/fb:like>');
(function() {
var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
s.type = 'text/javascript';
s.async = true;
s.src = 'http://connect.facebook.net/en_US/all.js#xfbml=1';
s1.parentNode.insertBefore(s, s1);
})();
//]]>
</script>
</div>
<!-- End Facebook button -->

<!-- Tweet Button -->
<div style="float:right; margin-right:11px;">
<a href="http://twitter.com/share?via=youraccount&amp;count=vertical" class="twitter-share-button">Tweet</a>
<script type="text/javascript">
var a = document.createElement('script'), b = document.getElementsByTagName('script')[0];
a.type = 'text/javascript';
a.async = true;
a.src = 'http://platform.twitter.com/widgets.js';
b.parentNode.insertBefore(a,b);
</script>
</div>
<!-- End Tweet Button -->
<!-- end #social --></div>
<!--=================== end.social buttons ==================-->
")


The reason I want to test the browser right within the social.php file is that I would ideally like to ad some additional content within this very file that should be included on every page and in any browser.

The reason for this is loading speed in firefox.

Now the example of the code above is giving me a lot of mistakes since I have no idea of what I have to do to get it to work.
11:07 pm on Aug 17, 2012 (gmt 0)

5+ Year Member



It has now been more than 2 days and i did not get a single reply, very unusual for webmasterworld members.
11:48 am on Aug 18, 2012 (gmt 0)

WebmasterWorld Senior Member swa66 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



The reason is that you post too much code.

Anyway read the manual on include: [php.net...]

See the file that reads "The include statement includes and evaluates the specified file."
Now look at your code

include("
<!--=================== social buttons ==================-->
<div id="social">
...

And you'll see the error of your ways.