Solved

Sessions for order form

Posted on 2004-08-19
3
208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP website on Linux - server DNS address could not be found. 18 87
MySQL limit and not so limited 13 40
curl parse data from site 20 42
MySQL-Design Help 12 43
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
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.

749 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