473,804 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3507
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_V ARS['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_V ARS['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_V ARS['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_V ARS['the_names']=array();
$HTTP_SESSION_V ARS['the_names'][0]='Joe Smith';
$HTTP_SESSION_V ARS['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
3887
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 new site I goto seems to prompt me to store their cookie. The other is Pocket IE on Pocket PC 2002, with the cookies set to 'enabled'. My problem is that the cookies dont seem to be being written with my ASP. I dont get the prompt to store...
20
3562
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
42820
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 way ... TIA
6
3062
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 cookie (say Response.Cookies ("TEST")) and you have a query string variable &test=x or &Test=x and you get Request.QueryString to parse the query string, the cookie that gets dropped matches the case of the query string, not what your code says. ...
2
3939
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? thanks Serge
1
1493
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 alternative way, ViewState will not be of much help. can somebody help me by suggesting a good way to solve my problem? Thanks much,
0
1869
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 http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=177245&SiteID=1 which discussed something similar, but I do not quite understand this or whether it is applicable to my scenario.
22
2950
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 using Perl on the backend, with Javascript providing limited frontend functionality. As an example, an expanding tree would be fully populated on the server-side and then presented to the browser, with Javascript and CSS being used to vary the...
13
1617
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. Briefly, the current time is encoded in a hidden form field when the page containing it is served. The script that processes the form checks the (new) current time against that in the form and rejects the submission if it is either too fast or...
0
9715
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10352
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10097
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6867
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5535
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3835
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.