Posted by LHO on 06/28/05 05:27
Hi
Below is the code from the book 'PHP By Example'.
I typed the code but it did not run the ELSE part. I believe the problem is
the $posted in 'if (!isset($posted))'
because it is never defined in the code. Where should I define it?
Your help is greatly appreciated.
Lawrence
<?php
/* ch11ex06.php - demonstrate serialize() and unserialize() */
// Main Program
if ($isset[$posted]))
{
// the form has not been posted; create an object, show that it works
// before it is serialized, then serialize it and show the serialized
string
// in a form.
echo 'Creating a new object...<br>';
$objDog = new dog;
$objDog->name = 'Spike';
echo $objDog->name . '<br>';
$objDog->Bark();
$strSerializedDog = base64_encode(serialize($objDog));
echo <<<END_HTML
<form action="$PHP_SELF" method="post">
<input type="text" name="serialized_data" value="$strSerializedDog">
<input type="submit">
</form>
END_HTML;
}
else
{
// the form has been posted; unserialized the posted string into an
object
// and use it to show that it still works.
echo 'Unserializing the object...<br>';
$objDog = unserialize(
base64_decode($HTTP_POST_VARS['serialized_data']));
echo $objDog->name . '<br>';
$objDog->Bark();
}
// class definition
class dog
{
var $name;
function Bark()
{
echo "Woof!";
}
}
?>
Navigation:
[Reply to this message]
|