View Single Post
  #8 (permalink)  
Old April 6th, 2005, 05:45 PM
omarosa omarosa is offline
Registered User
 
Join Date: Feb 2005
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hmm.... got it to work.

I'm not sure why it wouldn't write the cookie, but I tried using gzcompress/gzuncompress before/after writing the cookie and now it works. You can add as many constraints now and only call TestConstraints() once. Creating additional new requests and calling TestConstraints() was not actually doing what I expected, and was screwing up some other things as well.

I based my code off this example code from http://us3.php.net/manual/en/function.serialize.php :

Code:
<?php
$data[qwerty] = "blah";
$data[1][a] = "1aa";
$data[2][b] = "2bb";
$data[3][c] = ";;;;;;";
$data[name][first] = "Bob";
$data[name][last] = "Jones";
$data[val] = "This is a real long test string, to see how well the compression works!";

//To Serialise Call :
$string = gzcompress(serialize($data), 9);
setcookie("my_var", $string, time()+60*60*24*60, '/');
//print "String: $string\n<br>"; //uncomment to see serialized array

//To Unserialize Call
if (isset($_COOKIE[my_var])) {
  $array = unserialize(gzuncompress($_COOKIE[my_var]));

  echo "<pre>";
  print_r($array);
  echo "</pre>";
}
?>
Essentially, the only changes are (in request.phpm):

in __construct(...)
Code:
$origObj = unserialize(gzuncompress($cookieVal));
in TestConstraints()
Code:
$strSerialization = gzcompress(serialize($objToSerialize), 9);
HTH.