[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Sessions for order form

Posted on 2004-08-19
3
Medium Priority
?
212 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 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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 dynamically set the form action using jQuery.
Suggested Courses

656 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