[PHP] incrementing cookie

2005-09-14 Thread Ross
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.


Thanks,

Ross 

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



Re: [PHP] incrementing cookie

2005-09-14 Thread Jochem Maas

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 



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



Re: [PHP] incrementing cookie

2005-09-14 Thread Jochem Maas

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










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



RE: [PHP] incrementing cookie

2005-09-14 Thread George Pitcher
Hi,

 if (isset($add)) {
   $pakora++;
   setcookie(cookie[pakora], $pakora Pakora);
 }

If I'm not mistaken, you also need to be sure that you are writing your
script to html/display and not redirecting to another page after the cookie
has been set - as redirecting will not write the cookie.

Just my 2p.

George

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