Connecting Tech Pros Worldwide Help | Site Map

Alternative to Cookies

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 09:59 AM
kublai khan
Guest
 
Posts: n/a
Default Alternative to Cookies

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


  #2  
Old July 17th, 2005, 09:59 AM
scotty
Guest
 
Posts: n/a
Default Re: Alternative to Cookies

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:[color=blue]
> I am coming from (an elementary-level) javascript background. I set
> cookiesin select pages to see where the users are coming from and[/color]
where[color=blue]
> they are going. It works quite nicely except that I'd like to write[/color]
the[color=blue]
> 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[/color]
PHP[color=blue]
> 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[/color]
interest[color=blue]
> 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[/color]
file[color=blue]
> or database? Are there other, better means of doing the same? Where[/color]
can[color=blue]
> I find more info (I did check into php.net which I found[/color]
overwhelming)?[color=blue]
> TIA.
>
> KK[/color]

  #3  
Old July 17th, 2005, 10:00 AM
kublai khan
Guest
 
Posts: n/a
Default Re: Alternative to Cookies

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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.