[thelist] Some PHP & Image questions

Andrew Forsberg andrew at thepander.co.nz
Fri Mar 8 00:13:12 CST 2002


>I've got this figured out, but I don't know if I'm doing this the wrong
>way, or is there a better/efficient/easy way to do this. I am setting a
>cookie variable to the random index value :

Cookies are evil, more evil than client-side java dynamic menus. :-) <duck/>

TBH, I think it'd be much easier to do this with GET variables:
http://your.site.com/index.php?show=next&amp;id=2348
?show=prev&amp;id=2348
?show=random

i.e., figure out the random number on the target page, and forget
cookies altogether. Even better, drop the show=next / show=prev stuff
altogether, and create the target ids as links on the original page:
?id=2347 // prev
?id=2349 // next
?id=random // special case

But anyhow:

>$cookie  = $HTTP_COOKIE_VARS["RandomVal"];

[...]

>I wanted to store for that site. This time, I want to use cookies, and am
>running around in circles (or so it seems).

Lemme know where I'm going wrong with this:

- get a var ($cookie) from a cookie ($RandomVal)
- if it doesn't exist then set it to a random value
- otherwise
    - if they want 'next' then add 1 to $cookie (not THE cookie, just
a copy of the cookie's var)
    - if they want 'previous' subtract one from $cookie

- If -- there's no cookie set then a new cookie is created, but the
current page is kinda stuffed, because it can't find out what that
value is. If this is the source of the problem, then set $cookie to
the random number, and then set the real cookie $RandomVal to
$cookie's value.

- Otherwise -- there is a cookie, so work with $cookie and add or
subtract. But this isn't going to affect the real cookie... clicking
'next' 'next' 'next' is going to return the same page because the
real cookie is not altered, only the local variable $cookie (am I
sick yet of differentiating between the 'real' cookie, i.e.
$RandomVal and the not-really-a-cookie-but-called-a-cookie $cookie?
save yourself a debug nightmare and change those var names :-) ).

My vote, FWIW, is to drop cookies entirely and use GET vars instead.

Cheers
Andrew


--
Andrew Forsberg
---
uberNET - http://uber.net.nz/
the pander - http://thepander.co.nz/



More information about the thelist mailing list