|
Posted by Jochem Maas on 09/14/05 16:47
ross@aztechost.com wrote:
> Thanks for your reply,
yeah but that doesn't mean you have to start replying to just me,
keep your replies on list please - it helps others, and stops me from
getting the feeling I'm your personal bug fixer.
>
> This is what I have so far
>
> if (isset($add)){
>
> $pakora++;
$pakora will only exist if you set or if register_globals
is turned on. (I get the feeling you have register_globals turned on -
not the recommended setting IMO)
> setcookie("cookie[pakora]", "$pakora Pakora");
try dumping the contents of $_COOKIE:
var_dump($_COOKIE);
I would imagine the following gives you the number you are looking for:
echo intval($_COOKIE['cookie']['pakora']);
so...
<?php
if (!isset($_COOKIE['cookie']['pakora'])) {
$pakora = 0;
} else {
$pakora = intval($_COOKIE['cookie']['pakora']);
}
if (isset($add)) {
$pakora++;
setcookie("cookie[pakora]", "$pakora Pakora");
}
> }
>
>
> I just cannot seem to get the syntax right. when I try and use
> $_COOKIE['pakora'] i get an undefined index error. I am trying to
> increment the value of $pakora by 1 evert time .
>
> thanks again,
>
> Ross
> ----- Original Message ----- From: "Jochem Maas" <jochem@iamjochem.com>
> To: "Ross" <ross@aztechost.com>
> Cc: <php-general@lists.php.net>
> Sent: Wednesday, September 14, 2005 1:57 PM
> Subject: Re: [PHP] incrementing cookie
>
>
>> Ross wrote:
>>
>>> Hi,
>>>
>>> I want to increment a cookie by 1 every time a click a button
>>>
>>> if (isset($add) {
>>>
>>> $number++;
>>> setcookie("cookie[number]", "$number Is the number")
>>>
>>> }
>>>
>>> I know I should retireve the cookie value for $number but the problem
>>> is it has 2 bits, a number and a bit of text.
>>
>>
>> in your case this can be done simply:
>>
>> $number = 99;
>> $string = "$number Is the number";
>> echo "the number is ",intval($string),"\n";
>>
>> this works because the number is at the start of the string...
>> (and because of the cool way the made type conversion work in php)
>> to find out more search/read the manual on the subject of
>> typecasting/conversion.
>>
>>>
>>>
>>> Thanks,
>>>
>>> Ross
>>
>>
>>
>>
>>
>
[Back to original message]
|