Solved

Sessions for order form

Posted on 2004-08-19
3
203 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
This article discusses how to create an extensible mechanism for linked drop downs.
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…
The viewer will learn how to count occurrences of each item in an array.

757 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

18 Experts available now in Live!

Get 1:1 Help Now