473,657 Members | 2,504 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP & Cookies order form

Hi chaps,

I'm relatively new to the language, but I want to create a simple order
form using PHP and cookies. Please let me know if there's a better way
in this situation, database isn't availible.

What I'm trying to get is this:

1) Variable(A) passed from HTML page to script.
2) Script checks for cookie.
3) If no cookie, script creates one, Variable(A) the value.
4) If cookie, script adds Variable(A) value.

Then the script should produce an "order form" type page, listing the
variables within the cookie.

I'm new to PHP and I have no experience of cookies. I may be going about
this the wrong way, so please let me know!

Many thanks for any help,

- Daniel
Jul 17 '05 #1
3 5887
Tinkering with browser cookies directly is so...passe. Use PHP sessions
instead:

<?php

session_start() ;

if(is_array($_S ESSION['orders'])) {
$_SESSION['orders'] = array();
}
array_push($_SE SSION['orders'], $a); // from your form

?>

Uzytkownik "Daniel Ruscoe" <co*****@websit e.plz> napisal w wiadomosci
news:MP******** *************** *@news.btopenwo rld.com...
Hi chaps,

I'm relatively new to the language, but I want to create a simple order
form using PHP and cookies. Please let me know if there's a better way
in this situation, database isn't availible.

What I'm trying to get is this:

1) Variable(A) passed from HTML page to script.
2) Script checks for cookie.
3) If no cookie, script creates one, Variable(A) the value.
4) If cookie, script adds Variable(A) value.

Then the script should produce an "order form" type page, listing the
variables within the cookie.

I'm new to PHP and I have no experience of cookies. I may be going about
this the wrong way, so please let me know!

Many thanks for any help,

- Daniel

Jul 17 '05 #2
Daniel Ruscoe wrote:
Hi chaps,

I'm relatively new to the language, but I want to create a simple order
form using PHP and cookies. Please let me know if there's a better way
in this situation, database isn't availible.

What I'm trying to get is this:

1) Variable(A) passed from HTML page to script.
2) Script checks for cookie.
3) If no cookie, script creates one, Variable(A) the value.
4) If cookie, script adds Variable(A) value.

Then the script should produce an "order form" type page, listing the
variables within the cookie.


Do you need a cookie? Do you need to know the value of the data beyond
the order form page? Could you send data straight to the order form page
using forms, and perhaps hidden form fields?

If you do need to keep the data for several pages, then using PHP
sessions may be useful. Sessions use a cookie to store a session key
that points to a set of session data on the PHP server (though make sure
to think about security of session variables and whether there's a risk
of the session keys being intercepted over open connections). See the
Session handling functions (chapter XCV) in the PHP user manual.

If you need to store the data on the user's machine for more than
several pages, e.g. for several hours, days, months, or years, then
cookies are the way. Again, make sure to think about security of data
being stored on the remote machine, and about transmitting the data over
open (non-encrypted) connections.
--
Bob
London, UK
echo Mail fefsensmrrjyahe eoceoq\! | tr "jefroq\!" "@obe.uk"
Jul 17 '05 #3
In article <lb************ ********@comcas t.com>, Chung Leong says...
Tinkering with browser cookies directly is so...passe. Use PHP sessions
instead:

<?php

session_start() ;

if(is_array($_S ESSION['orders'])) {
$_SESSION['orders'] = array();
}
array_push($_SE SSION['orders'], $a); // from your form

?>


Thanks for that, I'm beginning to get the basics now. I've looked up
sessions and I see how they work. Looks like the perfect solution.

I'm stuck trying to figure out how I would add multiple items to a
session.

Say I want a form on one page, when the submit button is clicked 4
variables are sent to a PHP script to be added to a session.

Then I'd need that script to list them in an order form style:

Title Title Title Title
Variable1(A) Variable1(B) Variable1(C) Variable1(D)

With the ability to add more sets of variables afterwards to give:

Title Title Title Title
Variable1(A) Variable1(B) Variable1(C) Variable1(D)
Variable2(A) Variable2(B) Variable2(C) Variable2(D)

Can anybody point a beginner in the way of some code?

Thank you.

- Dan
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1798
by: John | last post by:
I am storing user names and addresses in cookies so that they do not have to enter them in forms. But now if I try to send the form with new data, the data in cookies is always called when I press the submit button. The data that I have entered get deleted and the data in the cookies is submitted. This also happens in scripts where I am not even using cookies to set the forms. How do I solve this problem? Thank you John
0
1435
by: Sam | last post by:
I am trying to pinpoint down a random response.redirect error message. "Object Moved To Here". I think it is due to the following order in which I am assigning cookies and redirecting: 1. I set the cookie - Response.Cookies("name").Values ("val") = ... 2. I redirect response.redirect("...") Is this legal. The problem is 85% of the time it works so I need somebody else's opinion.
9
3054
by: SHarris | last post by:
Hello, In our new intranet ASP.NET project, two requirements are that the browser accept cookies AND JavaScript. We are requiring the use of Internet Explorer 6+. 1. Using C# in an ASP.NET application, how can we code the project to check to make sure the browser accepts cookies? 2. Where would we put this code? In Global.asax? 3. Using C# in an ASP.NET application, how can we code the project to detect and make sure the browser...
2
6950
by: Luis Esteban Valencia Muñoz | last post by:
I'm working on a web scraping application that needs to log into a website before it can get the data to scrape. I've always been confused about how the HttpWebRequest and HttpWebResponse objects work together with cookies, and was hoping that someone here could clear it up for me! Here's the steps I need to accomplish: 1) Set two cookies containing information I already have 2) Request the login page URL, and save a third cookie that...
16
11043
by: Cheung, Jeffrey Jing-Yen | last post by:
I have a windows form application that generates a request, downloads an image, and waits the user to enter in login info. Unfortunately, this image is dynamic and based on session data. I have read documents on the CookieCollection property of HttpWebRequest. Currently, I have the functionality in my code to be able to accept cookies, and return them upon a new HttpWebRequest; however, upon further inspection of the returning...
6
6442
by: Paul | last post by:
Here is a question that should get everyone going. I have an ecommerce site where I need to pass the order_id to every page. So which method is the best practice to pass this variable between pages: Cookies or Session variable or by the HTTP header (either GET querystring or POST form)? I do not like to use sessions because they time out after 20 minutes of inactivity.
2
2283
by: Esa | last post by:
Hi, I'm having problems with one strange web system where submitting an application and making queries about its handling status require a series of form submits and response parsing - all in HTML. Luckily other interfaces are "modern" using xml file up/downloads without any difficulties... I'm not very used to .NET-environment yet, so I'd appreciate some clues about the classes I should use to implement this stupid interface - stupid...
10
10772
by: Immortalist | last post by:
Various aquisition devices that guide learning along particular pathways towards human biases. And as E.O. Wilson might say mental development appears to be genetically constrained. (1) Language Aquisition Device (2) Color Aqusition Device (3) Sound Aquistion Device (4) Smell Aquisition Device (5) Touch Aquisition Device (6) Art Aquisition Device
7
5345
by: bhavin30 | last post by:
Is there a way to obtain user information (using LOGON_USER server variables) when you have set up the security to Anonymous Access? I have tried setting the security to both Anonymous + Window Integrated, without any luck. I'm using IIS 6.0 on Windows Server 2003 Thanks in advance!
0
8325
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
8844
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8518
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7354
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
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.