homepage Welcome to WebmasterWorld Guest from 54.161.133.166
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Yet another question about PHP Includes
Social buttons and browser testing right within the include file
AlexB77




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

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.

 

AlexB77




msg:4486052
 11:07 pm on Aug 17, 2012 (gmt 0)

It has now been more than 2 days and i did not get a single reply, very unusual for webmasterworld members.

swa66




msg:4486112
 11:48 am on Aug 18, 2012 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved