Passing Complex Values in a Querystring
string serialize ( mixed value )
mixed unserialize ( string str )
<html>
<?php
class someclass {
protected $someval;
public function setsomeval($newval) {
$this->someval = $newval;
}
public function getsomeval() {
return $this->someval;
}
}
$myclass = new someclass ( );
$myclass->setsomeval ( "Hello World!" );
$myarray = array ();
$myarray [0] = "Hello";
$myarray = serialize ( $myarray );
$myarray = urlencode ( $myarray );
$myclass = serialize ( $myclass );
$myclass = urlencode ( $myclass );
?>
</head>
<body>
<a
href="index.html?passedarray=<?php
echo $myarray;
?>. &passedclass=<?php
echo $myclass;
?>">Output Current Value</a>
<?php
if (isset ( $_GET ['passedclass'] ) && isset ( $_GET ['passedarray'] )) {
$newclass = new someclass ( );
$newclass = $_GET ['passedclass'];
$newclass = stripslashes ( $newclass );
$newclass = unserialize ( $newclass );
echo "Object: " . $newclass->getsomeval () . "<br />";
$newarray = array ();
$newarray = $_GET ['passedarray'];
$newarray = stripslashes ( $newarray );
$newarray = unserialize ( $newarray );
print_r ( $newarray );
}
?>
</div>
</body>
</html>
Related examples in the same category