Passing Variables into Flash using FlashVars

The trouble with Flash has always been the level of communication between Flash and the web page. While this isn’t a new topic, it’s one that many webmasters have a lot of issues with. This is written assuming someone already knows how their way around Flash or actionscript. Looking at the standard Flash embed code:

 Javascript |  copy code |? 
01
02
<script type="text/javascript">
03
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','100','height','100', 'wmode', 'transparent', 'bgcolor', '#000000','src','flashfile','FlashVars','var1=1&var2=','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','flashfile' ); //end AC code
04
</script>
05
<noscript>
06
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="100" height="100">
07
<param name="movie" value="flashfile.swf">
08
<param name="quality" value="high">
09
<param name="FlashVars" value="var1=1&var2=">
10
<embed src="flashfile.swf" FlashVars="var1=1&var2=" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="640" height="680"></embed>
11
</object>
12
</noscript>
13

In order for this to work, you need a copy of AC_RunActiveContent.js. It's literally everywhere on the Internet. Just Google it and take your pick.

In order for this code to work, the settings must be configured to work with your Flash swf. The above code will pass 2 variables, var1=$1 and var2=$2, using FlashVars. Your Flash code in actionscript can then be configured to read the variables within the Flash file using _root.var1 and _root.var2. What you choose to do with the information that gets passed is now up to you. For more information on how to use AC_RunActiveContent, visit the Adobe Knowledgebase.
Was this useful? Help share it:
  • Print this article!
  • Twitter
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Mixx
  • Fark
  • MySpace
  • Technorati
  • Reddit

Calling #PHP on #JSP / #Java Pages with Javascript – #js

Working with hacked together management systems that utilize both Java/JSP and PHP can be extremely annoying. However, jQuery has made our lives a lot easier by letting us call PHP using Javascript.

javaMost of us are script kiddies. Admit it, we like to build our own tools but whenever a shortcut comes into play, we take the high road. Can you really blame developers for choosing this route when time seems to always be a factor on the Internet. The issue is this leaves us with VERY hacky systems. We piece together and integrate but there are just things we can’t control. Particularly if we ever end up with anything that’s not open source.

Here’s a trick for pulling PHP into a JSP run page, or really any page for that matter, as long as it supposed Javascript. Generally speaking, all things support Javascript.

 Javascript |  copy code |? 
1
2
<script src="jquery.js"></script> 
3
<script type="text/javascript">// <![CDATA[
4
 
5
  $.get("/location/to/file.php", function(data) {
6
   $("#posthere").html(data);
7
  });
8
// ]]></script>
9


jQueryHere's how this works. jQuery we should all know. If you don't, go do some reading. It's a big deal.

$.get is from jQuery and it will pull the information over and display it.

#posthere is key. The
is where what you want to load will show up.

Pretty much from this point you're set. All you need to do is build the PHP file and everything will load up on the JSP pages. Remember, this can applied to any page that supports jQuery or Javascript.
Was this useful? Help share it:
  • Print this article!
  • Twitter
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Mixx
  • Fark
  • MySpace
  • Technorati
  • Reddit

User Authentication Through Twitter OAuth or cURL

Twitter offers 2 types of authentication. Using the standard cURL GET HTTP protocols or the new and fancy OAuth. cURL is easy, we all get it, and it works great. However, OAuth offers a wide range of fancy features, most importantly, securtiy.

Taken from the OAuth website – An oauthopen protocol to allow secure API authorization in a simple and standard method from desktop and web applications. It’s a terrific idea and I’m glad someone is coming out with it. To make things easier there are also developers who’ve already done the work for you. Here’s a pre-built script that does all the OAuth for you. There’s also a Beginners Guide.

When the benefits are increased security, a higher level of compatibility, and new fancy technology, why bother with cURL anymore?

It’s pretty simple. cURL is easier, and it doesn’t require anything beyond what we know. Setting everything up with OAuth takes a few hours to wrap your head around. Compared to figuring out OAuth, here’s how to connect with cURL.

 PHP |  copy code |? 
01
02
$loginUsername = "username";   
03
$loginPassword = "password";
04
 
05
$url = "https://twitter.com/statuses/followers/" . $username . ".xml";
06
 
07
$curl_handle = curl_init();
08
curl_setopt($curl_handle, CURLOPT_URL, $url);
09
curl_setopt($curl_handle, CURLOPT_HTTPGET, 1); //GET method
10
curl_setopt($curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); //basic authentication
11
curl_setopt($curl_handle, CURLOPT_USERPWD, $loginUsername . ":" . $loginPassword); //login
12
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false);
13
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); //Return the string
14
$buffer = curl_exec($curl_handle);
15
curl_close($curl_handle);
16

There you have it, you're logged in, or at the very least authenticated. Here's how to report back:

 PHP |  copy code |? 
1
2
// check for success or failure
3
if (empty($buffer) || strpos($buffer, "Could not authenticate you")) {
4
 $replyStatus = "Failed: Please check your username and password";
5
} else {
6
 $replyStatus = "Success: You are logged in.";
7
}
8

twit-folTwitter currently supports both without offering many benefits to either choice. cURL isn't really anything new but it's simple while OAuth will continue to develop. For serious developers who plan for longevity with their Twitter Application sites, I highly recommend taking the extra effort to at least understand OAuth enough to switch to it when they demand it. In the meantime, forget it and stick with cURL until the benefits outweigh the cons.
Was this useful? Help share it:
  • Print this article!
  • Twitter
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Mixx
  • Fark
  • MySpace
  • Technorati
  • Reddit

Parse a String with BB Code or RSS using PHP

Writing a function to parse BB Code and RSS Feeds each time you need them is a pain. Here’s a use function to throw into an include or just have on hand for later.

A little while ago I was stuck reading forum content outside of the forums. Pulling anything from the database is easy but without a nice set of functions to handle the odd strings that can somehow come out, it can be a little difficult. This function here made everything a lot better. Unless your forums look like this:

forums


This string handling function will do most of work for you once you set the tags. To improve on the function, just make parsed tags dynamic and pass them into the function when calling it.

 PHP |  copy code |? 
01
02
// Setup functions
03
function get_string_between($string, $start, $end){
04
        $string = " ".$string;
05
        $ini = strpos($string,$start);
06
        if ($ini == 0) return "";
07
        $ini += strlen($start);   
08
        $len = strpos($string,$end,$ini) - $ini;
09
        return substr($string,$ini,$len);
10
}
11
 
12
$fullstring = "this is my [tag]app[/tag]";
13
$parsed = get_string_between($fullstring, "[tag]", "[/tag]");
14
 
15
echo $parsed; // (result = app) 
16
Was this useful? Help share it:
  • Print this article!
  • Twitter
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Mixx
  • Fark
  • MySpace
  • Technorati
  • Reddit

BackType Tweetcount 1.2 with su.pr Short URL Support

The new BackType Tweetcount just launched last night. With a little work, it’ll support your very own custom shortened URL in the re-tweet. We like su.pr. Thanks to a bit of help from Michael of BackType, we’re able to figure out this mod overnight.

The previous version of BackType worked well but it always re-tweet your posts through awe.sm. That’s great and all, but what about the rest of us who have our own click tracking or even our own custom shorteners.backtype

So to make it better, last night we added a new option for developers to add a function into the code that will allow them to build their own custom functions and generate their own custom links. It’s really just a meta tag, “bttc_short_url” that gets generated the first time the post is viewed. Here’s the best part. Since the short url is generated the FIRST time everything is viewed. Just by browsing your pages, and olf non-syndicated links are automatically added into su.pr. If you use another shortening service, it’ll do the same for that too.

After grabbing the latest BackType Tweetcount, load up your favorite editing tool and add this function to the very bottom of the code:

 PHP |  copy code |? 
01
02
function bttc_supr($url) {
03
	$SU_username = "username";
04
	$SU_api = "api_key";
05
	$SU_url = "http://su.pr/api";
06
	$SU_vars = "?url=$url&login=$SU_username&apiKey=$SU_api";
07
 
08
	$curl_handle = curl_init();
09
	curl_setopt($curl_handle, CURLOPT_URL, $SU_url . $SU_vars);
10
	curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
11
	curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
12
	curl_setopt($curl_handle, CURLOPT_HTTPGET, 1); 
13
	$buffer = curl_exec($curl_handle);
14
	curl_close($curl_handle);
15
	//$SU_newURL = str_replace("su.pr/", "", $buffer);
16
	$SU_newURL = $buffer;
17
 
18
	return $SU_newURL;
19
}
20

As a quick note there. The commented out //$SU_newurl is for those that host their own url shortcodes on their domain using the su.pr htaccess modification.

Go to Line 180, insert this code:

 PHP |  copy code |? 
1
2
if (get_post_meta($post->ID, 'bttc_short_url', true) != '') {
3
    $button .= 'tweetcount_short_url=\'' . wp_specialchars(get_post_meta($post->ID, 'bttc_short_url', true), '1') . '\';';
4
}
5

Then go to Line 161, search for this code:

 PHP |  copy code |? 
1
2
if ($meta == '') {
3
	add_post_meta($post->ID, 'bttc_cache', time() . ':' . $cnt);
4
} else {
5
	update_post_meta($post->ID, 'bttc_cache', time() . ':' . $cnt);
6
}
7

Directly below the code, paste the following:

 PHP |  copy code |? 
1
2
if (get_post_meta($post->ID, 'bttc_short_url', true) == '') {
3
	$short_url = bttc_supr($url);
4
	if ($short_url) {
5
		add_post_meta($post->ID, 'bttc_short_url', $short_url);
6
	}
7
}
8

And that's it. Edit the first bttc_supr function into basically whatever you want, and the short URL will automatically generated the first time the posts are viewed. It'll let you re-tweet with your own custom links, and even add old content that you haven't added to your shortening admin pages for you. This is a pretty raw version of doing this. BackType will be launching an updated version soon with these modifications to make it easier for users that don't want to edit as much code.
Was this useful? Help share it:
  • Print this article!
  • Twitter
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Mixx
  • Fark
  • MySpace
  • Technorati
  • Reddit

SEO Friendly Links and .htaccess Hacks

I’m going to assume most people know how to activate or edit their own .htaccess files. If you’re not sure how to edit them then visit this link.

htaccess modifications can come in really handy when cleaning up some of the old management systems. For those that use Google Webmaster Tools, this can be a great way to clean up those nasty 404s. Also note the Bing Webmaster Area. Many developers don’t build for SEO purposes and let other guys deal with it later. Sometimes they will even request a fee. Here’s a few tricks to save a couple bucks or clean up some links.

1. Removing variables from your links

Ever wonder how sites that have nice friendly links to customer profiles do it? There are a number of methods but if you use php variables that come out like this:

http://www.mywebsite.com/index.php?profile=customer_name

Apply this short mod to your .htaccess file:

 HTML |  copy code |? 
1
2
RewriteRule ^profile\/(.*)$ index.php?profile=1 [L,QSA]
3

The result:

http://mywebsite.com/profile/customer_name

SEO-Friendly-Images-Titles


Nice friendly links that everyone understands. Even the users.



2. SEO Friendly 301 Redirects

This is probably the simplest and most useful htaccess. As developers, we change our minds all the time. If those changes ever include changing post names, moving folders, or just altering a link. Google Webmaster Tools is going to come knocking with a 404 error within the next couple days. Fix it with this:

 HTML |  copy code |? 
1
2
Redirect 301 /path/to/old/location /new/location
3

/new/location can also be a link like http://new_website.com




3. Custom Error Pages

These just help you make a nice polished site. Particularly the 404 error page.

 HTML |  copy code |? 
1
2
ErrorDocument 401 /error/401.php
3
ErrorDocument 403 /error/403.php
4
ErrorDocument 404 /error/404.php
5
ErrorDocument 500 /error/500.php



4. Block IPs Using htaccess

Handy when you just don't like someone, or a country, or you just hate that IP block

 HTML |  copy code |? 
1
2
allow from all
3
deny from 145.186.14.122
4
deny from 124.15



5. Prevent Hotlinking

I get a lot requests for this one.

 HTML |  copy code |? 
1
2
Options +FollowSymlinks
3
# Protect Hotlinking
4
RewriteEngine On
5
RewriteCond %{HTTP_REFERER} !^$
6
RewriteCond %{HTTP_REFERER} !^http://(www.)?domainname.com/ [nc]
7
RewriteRule .*.(gif|jpg|png)$ http://domainname.com/img/hotlink_f_o.png [nc]
8

For more dry information on .htaccess. Here's a great blog on it:

http://htaccess.wordpress.com/tag/htaccess-mod-rewrite/
Was this useful? Help share it:
  • Print this article!
  • Twitter
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Mixx
  • Fark
  • MySpace
  • Technorati
  • Reddit

OnlyWire – Annoying but Helpful

After spending about 4 to 5 hours on setting a whole chain of accounts for OnlyWire, I’d be holding back if I didn’t discuss it. Since the beginning on time (Internet time), webmasters have been looking for methods of auto-submitting. I can’t count how many companies that I have been a part of that have tried to develop their own auto-submission services to their own sites or to their partners.


Why do companies have such a hard time? We’re fickle. The “team” changes it’s minds frequently. Worse yet, the Internet keeps changing… very very fast. So some could say it’s hopeless. Whenever the technology starts to complete, something new comes out and we’re stuck rebuilding an automated system… kind of defeats the purpose.

Thank god someone made a business out of this. While it doesn’t cover every blog or social networking site out there, at least it does the major ones. And for guys like me who don’t have the time, it’s great.

While this service is great, this very well hidden Wordpress Plugin for it is even better. Don’t say I never offered you anything. This is something I snuck off the BlackHatWorld Forums so credit belongs to them.

Download the Plugin
Was this useful? Help share it:
  • Print this article!
  • Twitter
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Mixx
  • Fark
  • MySpace
  • Technorati
  • Reddit

1

3aiwpg5y72
Was this useful? Help share it:
  • Print this article!
  • Twitter
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Mixx
  • Fark
  • MySpace
  • Technorati
  • Reddit

How to Post to Twitter using cURL

Having a choice of 50 Wordpress plugins are great when you are using Wordpress but what do you do when you have custom made software or don’t use Wordpress?

Using this handy cURL php code, you can post to Twitter from anywhere on your website. You can include the code as is, or just stick it into a function that you can include across all your scripts that need it.

 PHP |  copy code |? 
01
02
// Set username and password
03
$username = '$username';
04
$password = '$password';
05
// The message you want to send
06
$message = $TWITTER_POST;
07
// The twitter API address
08
$url = 'http://twitter.com/statuses/update.xml';
09
// Alternative JSON version
10
// $url = 'http://twitter.com/statuses/update.json';
11
// Set up and execute the curl process
12
$curl_handle = curl_init();
13
curl_setopt($curl_handle, CURLOPT_URL, "$url");
14
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
15
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
16
curl_setopt($curl_handle, CURLOPT_POST, 1);
17
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message");
18
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
19
$buffer = curl_exec($curl_handle);
20
curl_close($curl_handle);
21
// check for success or failure
22
if (empty($buffer)) {
23
//    echo 'message';
24
} else {
25
//    echo 'success';
26
}
27

I commented out the messages but I left them in for debugging purposes. Just uncomment then and start testing. Here's the end result... as if we didn't know what it would look like anyway.

cURL Twitter Post


This is really just a snippet, you can expand on this and even create forms that request the username and password for distributable scripts or replies from your traffic.
Was this useful? Help share it:
  • Print this article!
  • Twitter
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Mixx
  • Fark
  • MySpace
  • Technorati
  • Reddit

su.pr Traffic Results and API Tests

So I finally have enough data to report on the su.pr mods we made to our systems as discussed in the post “su.pr – cURL Links into your Account with Login/API”. They came out great. I really only started working with StumbleUpon a few weeks ago and we’re already seeing great results. For the most part, it really just started picking up after we installed su.pr.

Here’s a screenshot of the results since su.pr. You can tell right when we got it installed. The effects shows the next day.

su.pr traffic

su.pr traffic

Was this useful? Help share it:
  • Print this article!
  • Twitter
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Mixx
  • Fark
  • MySpace
  • Technorati
  • Reddit