Login - Register
All of the stuff, enjoy
Browse just the articles
Browse just the tutorials
Browse just the galleries
See what is cooking in the labs of Amatoc Industries
Paroozing our database of content eh?
Contact Chris and Amatoc Industries with questions or comments
About Chris and Amatoc Industries
 
Thumbnail for Simple PHP script to add dynamic Stumbleupon button

Simple PHP script to add dynamic Stumbleupon button


Written by Amatocianmonk
2008-12-17
This is a simple piece of code to add a dynamic stumbleupon button to your website.

We first need to get the current page url in order to create the link.
Here, $_SERVER["SERVER_NAME"] is the domain of your server (www.amatoc.com) and $_SERVER["REQUEST_URI"] is the current path (/folder/file.php). We append http:// to the front of those two server variables to return the full URL. So it all becomes http://amatoc.com/folder/file.php.

<?
$pageURL = 'http://';
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
?>


We then add the following code to create the link and display this stumbleupon button Stumbleupon review button,

<?
$pageURL = 'http://';
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
<a href="http://www.stumbleupon.com/submit?url=' . $pageURL . '" target="_blank"><img border="0" src="http://www.stumbleupon.com/images/su_micro.gif" alt="Stumbleupon button" /></a>
?>


That is all of the code that you need to generate your button for users to submit your page to stumbleupon without having to hard code it into every page. This is helpful if you want to do something like we have on this site.

If you would like to be more robust and verify the server port and append the proper URL if it isnt 80, you can use the code below.
$pageURL = 'http://';
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
echo('
<a href="http://www.stumbleupon.com/submit?url=' . $pageURL . '" target="_blank"><img border="0" src="http://www.stumbleupon.com/images/su_micro.gif" alt="Stumbleupon button" /></a>');
?>







Post a comment
Simple PHP script to add dynamic Stumbleupon button
Name
Email. Required, not published
Website

2000 character limit. Allowed html tags are <b><u><i>
Type captcha
Troy says:
2009-07-03

Now can you give us one to block it?
Amatocianmonk says:
2009-07-04

What do you mean "To block it"?
 
© Owner of Amatoc.com 2007-2009
All rights reserved
For permission to use content from this site, please use the Contact Form
~Logic and reason, above all things~