473,386 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

Jul 17 '05 #1
2 3485
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Brian Burgess | last post by:
Hi all, Anyone know of any special issues with storing cookies with ASP? I'm trying this with two browsers: One is IE 6.0 with cookies set to 'prompt'. This has been working properly as any...
20
by: Brian Burgess | last post by:
Hi all, Anyone know if this is possible? If so, on which page would the cookie be? .. On the page calling a function defined in the include file? thanks in advance.. -BB
43
by: Dimitri Debruyne | last post by:
Hi group I am in the process of developing a website in XHTML Strict and CSS. Is there a way to open a link in a new window without the use of frames or Javascript or something ? I didn't find a...
6
by: Mark | last post by:
Hi... I've come across some weird bug with Response.Cookies. Or maybe it will be called "by design" but for the life of me I can't figure out what purpose it would serve. If you're setting a...
2
by: sb | last post by:
As the session variable are not recommended, i search for an alternative to store my classe that i use and that i store in that session variable. is that the context that is the alternative? ...
1
by: Mujir | last post by:
Hi, I have used Session variables in my ASP.NET 2.0 application to save data across multiple pages. My production environment does not allow me to use session state. I have to find an...
0
by: =?Utf-8?B?QWltbGVzc1pvbWJpZQ==?= | last post by:
Hi, I need to call a session-enabled web service from a mobile client. But the ..NET Compact Framework does not support cookies. Is there a workaround/alternative for this? I found this link...
22
by: Dan Rumney | last post by:
Hi all, I've been writing Javascript for quite a while now and have, of late, been writing quite a lot of AJAX and AJAX-related code. In the main, my dynamically generated pages are created...
13
by: Ben Bacarisse | last post by:
A while back I suggested a method of using timestamps to filter out at least some automatic form postings. Now that I have tried it for about 10 months, I thought it might useful to report back. ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.