есть страница с урл который можно определить вот так: $url = $_SERVER['REQUEST_URI']; Есть переменная $price в которой случайно число из диапазона от 40 000 до 80 000; Dот мне нужно выводить на странице echo $price; чтобы эта переменная хранилась неделю. Cуть в том что у каждой страницы $price определятся случайным образом и сохраняется у пользователя в куках на неделю. Т.е он открыв эту же страницу увидит число из переменной которая хранится в куках. как сделать?
b3, разве куки пропусуются не для домена в целом ? При переходе на следующую страницу price просто перепишется же. ufaclub, предлагаю такой вариант - при заходе на страницу создать сереализованный массив с id страницы и price и записать его в куки, ну или сессию. Потом если массив уже есть просто дополнять его.
Куки можно назначить не на домен в целом а на директорию, в таком случае можно совместить с мод_реврайт и выдавать каждую страницу как будто в отдельной директории. Как вариант еще $price тоже в урл запихнуть через мод_реврайт + куки. На выходе получим адреса вида: www.site.com/page/911911/ Вот переменная $price = 911911 name = price expire = time()+60*60*24*7 path = /page/911911 value = 911911 Есть загвоздка, если страница одна, но каждому пользователю нужно выдавать разную цену, тогда все очень просто и даже мод реврайт не нужен. Но если страниц много, тогда : RFC2109 Code: 6.3 Implementation Limits Practical user agent implementations have limits on the number and size of cookies that they can store. In general, user agents' cookie support should have no fixed limits. They should strive to store as many frequently-used cookies as possible. Furthermore, general-use user agents should provide each of the following minimum capabilities individually, although not necessarily simultaneously: * at least 300 cookies * at least 4096 bytes per cookie (as measured by the size of the characters that comprise the cookie non-terminal in the syntax description of the Set-Cookie header) * at least 20 cookies per unique host or domain name User agents created for specific purposes or for limited-capacity devices should provide at least 20 cookies of 4096 bytes, to ensure that the user can interact with a session-based origin server. The information in a Set-Cookie response header must be retained in its entirety. If for some reason there is inadequate space to store the cookie, it must be discarded, not truncated. Applications should use as few and as small cookies as possible, and they should cope gracefully with the loss of a cookie.