Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Alternative to Cookies
- kublai khan
December 12, 2004, 10:32 pm
rate this thread
cookiesin select pages to see where the users are coming from and where
they are going. It works quite nicely except that I'd like to write the
data into a file and look at it. I have reached a dead end with JS it
seems. I have thought about implementing the same with PHP (I know
nothing about it but I'm willing to learn) but the disadvantage of PHP
as I understand is that the pages need to be refreshed in between
setting and reading the cookies. It seems to me that since my interest
is only in the value of the cookie, I could do away with this method
entirely and simply set a variable that is updated upon visiting a
page. My questions are:
Can I set a global variable whose value is updated as each page is
loaded? Can I check the value of the variable and dump this into a file
or database? Are there other, better means of doing the same? Where can
I find more info (I did check into php.net which I found overwhelming)?
Re: Alternative to Cookies
I hope you are doing well in you stately pleasure dome.
Below are a couple very simple examples. Apologies if they are too
Yes, you can pass standard local variables from form to form via
GET(url) or Post(form) as well as with Session / Global variables.
With session variables, the session has to be started first, perhaps as
your first page might be:
//now that the session is started, you can load a session variable with
what you want to pass,
//maybe a posted variable as in this example
when you arrive at another page as below, you can get the session value
or append to the value like this:
//now that the session is started, you can load the prior session
variable from prior page
//concatenate the next name
//then reload the session variable with the revised list
The session variable can be a standard array as well, loaded in the
same manner as other PHP arrays:
Obviously with arrays, you can organize your data more efficiently.
When you are done, you can pass the contents of the session variable to
your database by building custom queries with
Note: Users might have privacy settings set in such a way as to not
allow the passing of session variables. If you determine this ahead of
the client, you can auto-submit a form with hidden post variables to
pass to the next page. You can also put them in a database and track
them that way.
A simple but fairly thorough book to get review: PHP and MySQL Web
Development by Luke/Laura Welling
An incredible book to get review is: PHP Cookbook by David Sklar &
kublai khan wrote:
Re: Alternative to Cookies
I picked up PHP cookbook on your suggestion. It seems that cookies will
work fine for what I want to do. Sorry I didn't explain myself well.
BUT, analogous to what you have suggested, I wonder if setting a
session_id would be a better idea since the variable can be passed to
other pages & subsequently updated. Moreover, it also gets around the
issues with client permissions. Is this a viable idea?