SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: Session Problem
-
Nov 19, 2008, 17:31 #1
- Join Date
- Nov 2008
- Posts
- 3
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Session Problem
Hello,
I have a while loop that displays a books category, in each row, there's a session array that holds each row(book) ISBN.
Till here i have no pronlem, the code is displayed below.
The problem is that when the member clicks on the cart picture in any of those rows, how do i know that this session array has been selected? How i know which books was clicked?
I am stucked and i couldn't find what I need on google.
Thank you very much
Code:<?php if($_SESSION['authen']) { $_SESSION['item'][] = $row['isbn']; echo $_SESSION['item'][]; // I want to print this just for checking echo "</td> <td valign=\"top\" align=\"center\"> <p align=\"center\"><font face=\"Tahoma\" size=\"2\"> <a href=\"../shopping/cart.php\"><img border=\"0\" src=\"../images/cart.jpg\" width=\"69\" height=\"132\" alt=\"add to cart\"></a> "; } else { echo "</td> <td valign=\"top\" align=\"center\"> <p align=\"center\"><font face=\"Tahoma\" size=\"2\"> <img border=\"0\" src=\"../images/spacer.gif\" width=\"69\" height=\"132\">"; } ?>
-
Nov 19, 2008, 21:54 #2
Hiya, to identify an individual book you could assign an id to each one and then when you print each one out in your table, include the id in the url query string, eg: site.url/cart.php?bookid=1 then bookid=2 etc
With your session array question, the user has the session id stored within their web browser, so they'll always have the same session data between page clicks on your site. Though just looking that that bit of code, couldn't you print out the $row['isbn'] variable directly rather than pushing onto the session variable first?
Anyhoo hope thats some help!
-
Nov 20, 2008, 01:12 #3
- Join Date
- Nov 2008
- Posts
- 3
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi,
Thanks for your help.
Yes I think it is better to send each book id in the url.
I just want to hear your opinion about this: is it smthg not good or poor in programming to send variables in url?
-
Nov 20, 2008, 01:22 #4
- Join Date
- Apr 2008
- Location
- Riga, Latvia
- Posts
- 755
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi, there is nothing wrong per se in using GET variables - sending variables in URL.
Keep in mind though, that you need to protect yourself against CSRF (this paper describes both attack and ways to protect againt it).
-
Nov 20, 2008, 06:46 #5
- Join Date
- Nov 2008
- Posts
- 3
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I will read this paper now to protect my site.
But I wish that someone can give me an idea about my session array code.
I am wondering, when each row session array has been assigned a value, which is the isbn of the book, if the user chooses to add this book in this row to the cart, how i would know that he chose this book. how you would know that this element of this array was chosen?
Thank You
-
Nov 20, 2008, 08:30 #6
You could add each book id to a 'users selection' array in the session variable when the user selects a book, eg:
$userInput = 5; //book id passed in by the user
$_SESSION['userSelection'][] = $row['isbn'][5];
Bookmarks