Class Name: ReturnVars Date Created: 9/19/06 Author: Chase Spell Purpose: Stores variable/value pairs in an associative array. Echos the final product as a url-encoded string formatted as a GET request. Intended to be used to return data from a php script to a Flash movie, but could be used for any system that accepts GET statements for input.
By : Syntax
/**************************************** Class Name: ReturnVars Date Created: 9/19/06 Author: Chase Spell Purpose: Stores variable/value pairs in an associative array. Echos the final product as a url-encoded string formatted as a GET request. Intended to be used to return data from a php script to a Flash movie, but could be used for any system that accepts GET statements for input. *****************************************/
class ReturnVars {
var $CurrentVars; var $Vars = array();
function __construct() { //Properties $this->CurrentVars = 0; //Number of Var/Val pairs in the "Vars" array }
//Methods
//Adds a new var/val pair to Vars and updates CurrentVars function AddVar($name,$value) { //if ($name != "" && $value != "") { $this->Vars[$name] = $value; $this->CurrentVars = $this->CurrentVars + 1; //} }
//Removes var/val pair from Vars array, $name corresponds to an existing variable name in the array function RemoveVar($name) { if (array_key_exists($name,$this->Vars)) { unset($this->Vars[$name]); $this->CurrentVars = $this->CurrentVars - 1; } }
//For/Each loop goes through Var adding each pair to a string in this format: "(var)=(value)&" and //and echos that string for output function PrintData($printandexit = true) { $output = ""; if ($this->CurrentVars > 0) { foreach ($this->Vars as $var => $val) { $output .= urlencode($var)."=".urlencode($val)."&"; } echo $output; } else { echo "No data was returned."; } if ($printandexit = true) { exit; } } }
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.