Passing Complex Values in a Querystring : Query String « Form « PHP






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;
  ?>. &amp;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

1.Passing Numeric Values in a Querystring
2.Passing String Values in a Querystring
3.parse_str() function parses string into various variables, setting the variables in the current scope.
4.parse_str.php