Internet Commerce

Partners & Affiliates

Developer Channel


Featured Flash FLA
Gallery Downloads 11401 Flash Movies | 5 New Flash Movies Added
What's New | Top 100

Featured FLA

»  Author Miguel Panos
»  Title: Tarta
»  Description: It is a circle graph or pie chart that takes the data entered by user
»  More by Miguel Panos


Random FLAs | Add Flash Movie
Featured Flash Site
Gallery Downloads 4839 Flash Sites | 1 New Flash Links
What's New | Top 100 Flash Site

Featured Site

»  AuthorDeft Creative Ltd
»  Link: Home Page
»  Description: Portfolio site for .DeftCreative Ltd. A UK based web design studio specialising in flash websites, games and interactive CDROMs. With an emphasis on making things different.


Random Links | Add your own Flash Related Links
Flash Tutorials 1484 Tutorials 7 New Tutorials Added!
What's New | Top100

» Making Automatic Training Screen Capture Easily
» Create Undersea Life Animation
» Making Deinterlace Video with a low bitrate Easily
» How To Make A Simple Animation Using Christmas Clips
» Simple Step by step flash game tutorial Spot the diffrence
» How To Make A Moving Text Slide
» Create Flash Banner With Text Float Effect
» How To Make Zoo Photos Slideshow
» How To Make A Dolphin Photos Slideshow
» Unknown Tag: Title10
Random Tutorial | Add Site


Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


Tutorials Tutorials » Tips_And_Techniques

Categories setting a cookie with Flash and PHP
Author: William Clarkson | Website: http://www.nerds.clarksontechnology.com |

 
Page 1
1

Setting a cookie with Flash

Most web programmers know the value of using a cookie to store data between a users visits. Cookies keep passwords, shopping carts contents and preferences of many kinds stored on the user's computer until they need it. Flash provides us with the shared object that can either be set to be accessed only by the file that made it, or for any other swf file. For Example:

//make shared object and read values
var so:SharedObject = SharedObject.getLocal("foo", "/");
uname = so.data.email2;
pass2 = so.data.pass2;
email = so.data.email;
//write to sharedObject
so.data.curData=Date;
so.data.flush;

This works great if you want flash to read the variables later, but what if you need to access information in php but that has been written by flash? Or if you need to read in flash a cookie set by php?

Flash contains a command called loadVars() which as one may guess was made for loading a variable into flash. However when flash tries to load a variable from a php page all the script on that page is executed, thus giving all the power of PHP to Flash.

So to set a cookie from flash or to execute any php script from flash we only need one line of action script.

loadVariables("http://www.mysite.com/setCookie.php
?mycookie=name&myvalue=Bob",_root);

The code for the setCookie PHP is as follows

<?PHP
$mycookie=$_GET['mycookie'];
$myvalue=$_GET['myvalue'];
setcookie($mycookie,$myvalue,time() + 31536000);
?>

to read the cookie in Flash or PHP later use this script:

<?
$myvalue=$_cookie['cookieName'];
//write out for flash
echo "&myvalue=$myvalue";
?>

you can call this or any other php script by using the loadVariables method above. This will allow you to hook flash to Databases, Rss and many other web services

1

» Level Intermediate

Added: : 2006-06-09
Rating: 5.80 Votes: 5
Hits: 883
» Author
William Clarkson is a flash programer who has worked throughout the US and Asia. He now runs several websites and a consuliting company in Wisconsin
» Download
Download the files used in this tutorial.
Download (0 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!

Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10 9 8 7 6 5 4 3 2 1
Read or Post Comments