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.

[EMAIL PROTECTED] 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






-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to