OK, I don't have the problem any more but I decided to go ahead with the
post anyway (since I already wrote it up).
I solved the problem by turning off magic quotes in the php.ini file. I made
this file for the purposes of a training course I'm writing.

At the bottom of this email I've included the source.

The error is:
Warning: unserialize() failed at offset 8 of 157 bytes in [blah].php on line
17

I'm running PHP 4.1.1 on win2k testing with IE5.5 and also Netscape 6.2.1
There shouldn't be an issue with setting the cookie since I can successfully
display the serialised cookie (see debug line).

Thanks in advance.
[TK] 

Here comes the code.

<?php
    $needARefresh = FALSE ;
    if(isset($frmAction)){
        $token = array(
            'name'      => $frmName,
            'food'      => $frmFood,
            'colour'    => $frmColour,
            'petHate'   => $frmPetHate,
            'joke'      => $frmJoke
        ) ;
        $safeToken = serialize($token);
        setcookie("personalisedInfo",$safeToken);
        $needARefresh = TRUE ;
    }
    if(isset($_COOKIE["personalisedInfo"])){
        echo $_COOKIE["personalisedInfo"] ; //debug
        $arrayBack = unserialize($_COOKIE["personalisedInfo"]);
        $name       = $arrayBack['name'];
        $food       = $arrayBack['food'];
        $colour     = $arrayBack['colour'];
        $petHate    = $arrayBack['petHate'];
        $joke       = $arrayBack['joke'];
    } else {
        $name       = NULL ;
        $food       = NULL ;
        $colour     = NULL ;
        $petHate    = NULL ;
        $joke       = NULL ;
    }
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
        <title>PHP tutorial: serialize/unserialize</title>
    <?php if($needARefresh) { ?>
        <meta http-equiv="Refresh" content="0;URL=<?= $PHP_SELF ?>">
    <?php } ?>
</head>

<body>
<h1>The serializer()</h1>
<table>
<caption>A survey</caption>
<form action="<?= $PHP_SELF ?>" method="post">
<tr>
        <td align="right">your name:</td>
        <td><input type="text" name="frmName" value="<?= $name ?>"></td>
</tr>
<tr>
        <td align="right">favourite food:</td>
        <td><input type="text" name="frmFood" value="<?= $food ?>"></td>
</tr>
<tr>
        <td align="right">favourite colour:</td>
        <td><input type="text" name="frmColour" value="<?= $colour ?>"></td>
</tr>
<tr>
        <td align="right">pet hate:</td>
        <td><input type="text" name="frmPetHate" value="<?= $petHate
?>"></td>
</tr>
<tr>
        <td align="right">tell me a joke:</td>
        <td><textarea cols="" rows="" name="frmJoke"><?= $joke
?></textarea></td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="frmAction" value="send"></td>
</tr>
</form>
</table>
</body>
</html>

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

Reply via email to