Solved

Sessions for order form

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

813 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

14 Experts available now in Live!

Get 1:1 Help Now