472,805 Members | 1,206 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 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 3456
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. ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

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.