- Home
- Tutorials
- Flash
- Intermediate
- E-Cards and other Dynamic Systems

The PHP: storing / retrieving the data
This section of the system is the part where we 'store' the data for use later. Before you ask, yes you can do this with CGI or ASP, or JSP, or whatever scripting language you know, but I know PHP so that's what I've used. The code goes like this:
<?php
$fd = fopen("$session.txt", "w");
fwrite($fd, "locationString=$layoutString&contentLoaded=true");
fclose($fd);
mail($email, "You have recieved an E-Card", "You have recieved an E-Card, an online card create by a friend or associate. To view your e-card please goto http://www.YOUR-URL.com/e-card/reader.php?session=$session", "From: PHPMailer Reply-To: $from X-Mailer: PHP/" . phpversion());
?>
It's not as bad as it looks. All it does is:
- You passed a variable 'session' before (from your write.swf) which was a unique string. This takes that string and constructs a text file with that name. Yes a text file, this isn't a database tutorial, text files are good because they can be deleted later easier than database entries. Into that file it writes the layoutString that you passed from writer.swf and a constant variable contentLoaded which is assigned the value true and used for determining (later on) if all the variables are loaded yet.
- Next it sends an email off to the email address you specified in the 'email' input field in writer.swf, with the Subject: "You have received an E-Card", and a body with a bit of info in it. The important bit in this info is the line that reads: .../reader.php?session=$session what this does is sub in the session variable, so if my session was "123" this line would read "reader.php?session=123". Why's that important? Because the user's computer needs to know which text file their specific card's data is stored in. If I have 100 people reading this tutorial every day, I don't want to your cards to get mixed up, so I separate their data into randomly named text files, and send you a URL with the name of your file included...
So now we all know that the session is passed via the URL into the reader.php.
Reader.php
All this does is embed the session string into the reader.swf. It uses the simple infix URL syntax, similar to the GET method. I've discussed this in a previous tutorial but I forget which. Basically if I open a flash file using the URL followed by a variable name and value, Flash will import that variable and value. For instance: myFile.swf?myVar=123 will create a new String variable in myFile.swf called myVar. Note that as with loadVariables this variable is loaded in as a String so it's value will be "123" (the String) not 123 (the number). So the important bits of code in this PHP file are:
<PARAM NAME=movie VALUE="reader.swf?session=<?php echo $session; ?>">
and
<EMBED realsrc="reader.swf?session=<?php echo $session; ?>" src="http://www.actionscript.org/dev/admin/reader.swf?session=<?php echo $session; ?>" ...
So this parses our session variable and loads it into the reader.swf file, which we will now examine...

