Solved

Sessions for order form

Posted on 2004-08-19
3
204 Views
Last Modified: 2008-03-06
hey people, ok, i have a gallery of pics on one page (php) and a seperate page is an order form (php).

Im trying to get it so that the user clicks on a link next to an image which will then take the user to the order form and display the name of the image they just click on.

i understand that i need to use sessions for this but am not sure how to as the user may wish to go back to the gallery and add other images to the order form. How do i go about this?

Can anyone please give me an example of how to do this with some code.

Thanks in advance!
0
Comment
Question by:mattdye
3 Comments
 
LVL 3

Accepted Solution

by:
Boris Aranovich earned 250 total points
ID: 11856142
Do you know how to work with sessions in general?
If not, try: http://www.php.net/session

Anyhow, what you have to do is session_start() on the beginning of the pages.
http://www.php.net/manual/en/function.session-start.php

Now, after you click on some image, it should send the image ID to some page that will add it to the session, for example:
$_SESSION['images'][] = (int)$id;
or
$_SESSION['images'][(int)$id] = $imagename;

then, it should redirect the script to the order form page.
There, the page should check for all the values in $_SESSION['images'] (with foreach() for example), and do whatever you need to do with them, like fetching the image names from DB or whatsoever.
The values should exist in the next page, if there is session_start(), and no problem with the session settings.
If the cookies are disabled, you'll have to forward the PHPSESID in the URL of the forwarder, so it'd keep on same session between the pages.

Next time you'll be both on the gallery pages, or the order-form page, the $_SESSION should be identical between them, meaning that you'll always have $_SESSION['images'] inside, which will contain all the images that you once selected.

To unselect an image, just have to use unset($_SESSION['images'][$index]).

This is a very simple example of how it should be done, and you should consider security checking and perhaps a better method to do this. Though this method should work just fine.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
calculated column 12 74
Calculate values in an array 18 32
What is the best PDF generator to use? 1 23
Method for submitting dynamically created rows 20 13
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now