How to Tweet your Knol Updates (Page 2)

A Tutorial

Wouldn't it be super, if after you update a knol article, you could tweet your followers about it? Well now you can.

Authors

Written 2010 by Will Johnson Jr, you can email me at fft2001@aol.com
or post your comments for public view far below.
Creative Commons Attribution 3.0 License


<-- Back to How to Tweet your Knol Updates (Page 1)
--> Forward to How to Tweet your Knol Updates (Page 3)

Okay, so on Page 1 we figured out that we can have a pretty image like the tweety bird thing, and we can make it so that when we click on it, some action occurs.  And we can build our pseudo-GET URL to pass arguments from our Knol page to our PHP program, although we have to manually embed them.  I really don't know if we're going to need to do that yet or not.  We're just sort of randomly exploring the universe here, we may bump into a few comets on the way you never know.

So here's the code, so far, that we think we might be able to use on any Knol article, to Tweet our own updates to Twitter:

<a href="http://www.penguins.com/twitmyknol.php?Prefix=I_just_updated_my_article&Title=How_to_Tweet_your_Knol_Updates"><img src="http://s.twimg.com/a/1265999168/images/default_profile_1_normal.png"></a>

Stop jumping ahead!  I know what you're thinking, now just knock it off and be patient!


Next, can our PHP program know the URL that we came from?  And maybe even it's Title?  If so, then we wouldn't have to pass these things as arguments in the URL itself.

Let's try this code
<?php
function curPageURL() {
 $pageURL = 'http://'. $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}

echo "The current page URL is ".curPageURL();
?>

Does that work?

<?php
function curPageName() {
 return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}

echo "The current page name is ".curPageName();
?>

Let's put it all together so far and see.  Click the birdy and see if it works.



Oh poop!  What we get is only the URL and name of the destination we're at, not what URL referred us which is what we really want!  Back to the drawing board with us.

Oh wait!  There is an environment variable which is set called HTTP_REFERER.  Some online discussions say that some webservers are blanking this out or allowing their users to do so, but let's see if Knol does that or not.  At least we'd be able to get the URL if not the title.  Here's the code:

<?php

$ref = getenv("HTTP_REFERER");
echo $ref;

?>


Let's try again using this new idea.  Click the birdy


Hey that works!


<-- Back to How to Tweet your Knol Updates (Page 1)
--> Forward to How to Tweet your Knol Updates (Page 3)