close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Storing session or cookie

Thread began 5/26/2018 8:24 am by Kumel | Last modified 7/12/2018 8:48 am by Ray Borduin | 2111 views | 9 replies |

Kumel

Storing session or cookie

I have to types of users.
1 - Logged in user.
2 - Guest.

Login user has a UserID Session to be used if any record is inserted.

In such case for Guest, I would like to store data like inserting a record using cookie.

Example:
Table named "Data" contains : DataID DataUserID DataName

Currently if logged in User insert a record into Data table we are storing session ID of user.
But in case of guest what needs to be done.

Sign in to reply to this post

Ray BorduinWebAssist

I'd probably just insert a 0 for guest users. I'm not sure I understand your question.

Sign in to reply to this post
Did this help? Tips are appreciated...

Kumel

I thought zero itself for guest users but how do we then know individual records of that user?

Let's say a user, add products into "Cart". "Cart" is a table, it contains: CartID, CartProductID, CartUserID, CartPrice.
Now when a user adds a record CartUserID is taken from session if exists else it takes 0, as guest user.
But how can each guest user view his cart ?

Sign in to reply to this post

Ray BorduinWebAssist

Well you couldn't. You would need a way to identify the user. I need to know the full description of what you are trying to do before I can advise you on how to accomplish it.

You could use a SessionID instead of UserID in the Cart table to keep identification of the guest cart items.

Sign in to reply to this post
Did this help? Tips are appreciated...

Kumel

I m creating an eCommerce kinda website. Users can add products to Cart. This is just like I created tables as Cart, Products, Users.
For Storing UserID in Cart it's storing using SESSION['SecurityAssist_UserID']

The user doesn't really have to log in to add products to the cart.

The user should be able to add products to the cart irrespective of user login. The individual guest user can view their own cart.

Sign in to reply to this post

Ray BorduinWebAssist

The session_id() value is unique to each browsing session. You could use that instead of the UserID from the session to work for both logged in users and guest users.

Sign in to reply to this post
Did this help? Tips are appreciated...

Kumel

oh ok. I seem to get the point. So how is it done? random session values on page load? How do we do this?

Sign in to reply to this post

Ray BorduinWebAssist

The session id is automatically created by the php server as long as the session has started. You can start the session with code on the top of the page like:
<?php @session_start(); ?>

Then you can use the id at any time with: <?php echo(session_id()); ?>

Sign in to reply to this post
Did this help? Tips are appreciated...

Kumel

How can i use this same login in where clause?
My Codes:


$session = ''.session_id().'';

$query_Cart = "SELECT * FROM Cart WHERE CartSessionID = '.$session.'";



Nothing is appearing even after data exist.

Sign in to reply to this post

Ray BorduinWebAssist

That should work. Did you add @session_start(); above it somewhere on the page?

Sign in to reply to this post
Did this help? Tips are appreciated...
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...