By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,204 Members | 1,212 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,204 IT Pros & Developers. It's quick & easy.

Alternative to Cookies

P: n/a
I am coming from (an elementary-level) javascript background. I set
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)?
TIA.

KK

Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hello,

I hope you are doing well in you stately pleasure dome.

Below are a couple very simple examples. Apologies if they are too
simple.

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
follows:
your first page might be:

<?php
session_start();
$name=$_POST['name'];
//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
$HTTP_SESSION_VARS['the_names']=$name;

?>

when you arrive at another page as below, you can get the session value
or append to the value like this:

<?php
session_start();

$another_name=$_POST['another_name'];
//now that the session is started, you can load the prior session
variable from prior page
$the_names_are=$HTTP_SESSION_VARS['the_names'];
//concatenate the next name
$the_names_are=$the_names_are."<br>".$another_name ;

//then reload the session variable with the revised list
$HTTP_SESSION_VARS['the_names']=$the_names_are;

?>

The session variable can be a standard array as well, loaded in the
same manner as other PHP arrays:
$HTTP_SESSION_VARS['the_names']=array();
$HTTP_SESSION_VARS['the_names'][0]='Joe Smith';
$HTTP_SESSION_VARS['the_names'][1]='Steve Jones';

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
your variables.

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
time, you can pass variables via URL or, if Javascript is enabled on
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 &
Adam Trachtenberg
Scott

kublai khan wrote:
I am coming from (an elementary-level) javascript background. I set
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)? TIA.

KK


Jul 17 '05 #2

P: n/a
Hi Thanks. No pleasure dome here when I'm out here trying to conquer
PHP :)
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?
TIA

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.