Re: serialize and unserialize

From: Date: Mon, 22 Dec 2003 17:15:44 +0000
Subject: Re: serialize and unserialize
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-173161@lists.php.net to get a copy of this message
You should use stripslashes to get rid of escaped characters in $_COOKIE['data']. Then remember to use addslashes when you want to use $data or $chksum in sql queries. webmaster@multiwebmastertools.com wrote:
Hello all i need a little help with serialize and unserialize here is my code <?php session_start();
if(!isset($_COOKIE['data'])) {                           //Check to see if cookie is there.
include("cookie_num.dat"); $y = "$password";
                                  //Assign a special number for each cookie.
$data = array('x' => 'cart', 'y' => $password); session_register("y"); $var = serialize($data); //$chksum = md5($data . md5('secret salt here')); //$var = serialize(array($data,$chksum)); setcookie('data', $var, time() + 3600); } else { $var = unserialize($_COOKIE['data']); list($data, $chksum) = $var; if (md5($data . md5('secret salt here')) == $chksum) { // Data is valid $data = unserialize($_COOKIE['data']); list($y, $chksum) = $data; $x = $data['x']; $y = $data['y']; session_register("y"); } //session_register("y"); } ?> the problem is when i try to pull it back out to use the number that is generated by $password it gives me this error Notice: unserialize(): Error at offset 9 of 118 bytes in c:\program files\apache group\apache\htdocs\header.php on line 24 any ideas towards fixin this would be appreciated
                           


« previous php.general (#173161) next »