TechniqueUse the session_encode() and session_decode() functions: write.php: <?php session_register("monkey"); $monkey = array("see", "do"); $string_monkey = session_encode(); $fp = @fopen ("save_monkey.txt", "w") or die ("Cannot open save_monkey.txt"); @fwrite ($fp, $string_monkey); @fclose ($fp) or die ("Cannot close save_monkey.txt"); print "Actions Written"; ?> read.php: <?php $fp = @fopen("save_monkey.txt", "r") or die("Cannot open save_monkey.txt"); $data = fread($fp, filesize ($fp)); @fclose ($fp) or die ("Cannot close save_monkey.txt"); session_decode($data); foreach ($monkey as $action) { print "$action\n<br>\n"; } ?> DescriptionThe session_encode() function takes all the current session information and encodes it in to a string that can be parsed by the session_decode() function. The session_decode() function then parses that string and creates the session variables from the information contained within that string. |