Page 1 of 2

Shopping Cart

Posted: Wed Sep 04, 2002 7:22 am
by Nargule
I am writing a shopping cart in php which stores the shopping cart data in a mySQL db.

Right now the cart I have constructed stores the user's IP address, Item ID, and quantity in a table when they click "add to cart". When they go to view their cart, it simply selects items from the table that matches the user's IP.

I have some concerns about doing it this way, but I don't know how else to go about it.

What other ways are there to uniquely identify a client?

A second question, after calculating numbers, 0's after a decimal point get dropped i.e. $17.90 appears as $17.9
Anyone know an easy way to force the 00's after the decimal?

Thanks in advance,

Tom

Posted: Wed Sep 04, 2002 7:44 am
by gite_ashish
hi,
What other ways are there to uniquely identify a client?


The best & reliable way is to use sessions.

See PHP manual:

:idea: http://www.php.net/manual/en/ref.session.php

You also need to add (registation,) login scripts into ur shopping cart.

Posted: Wed Sep 04, 2002 7:58 am
by gite_ashish
hi,

See this for retaining 0:

Code: Select all

<?php

    $i = 17.90;

    echo "Total: \$ $i<P>";

    // 1
    echo 'Total: $ ' . number_format( $i, 2 ) . '<P>';

    // 2
    printf( "Total: \$ %.2f<P>", $i );

    // 3
    $j = sprintf( "%.2f", $i );
    echo "Total: \$ $j<P>";

?>

See PHP man:

:arrow: http://www.php.net/manual/en/function.number-format.php
:arrow: http://www.php.net/manual/en/function.sprintf.php


regards,

Posted: Wed Sep 04, 2002 8:04 am
by PingLeeQuan
Hello... i ran intot he same thing a while back. I can assure you that using IP will not work for the simple fact that many corporations/ISPs..... use IP Address translation. THis means that many users from (lets say ALCOA, INC.) will have the same IP address. Therefore, all users can see other orders as part of thier cart.

The best way is to use sessions in conjunction with Cookies. If Cookies is not an option, then you have to append the ID and Token of the sesison at the end of each link in your site.

hope that helped.

Posted: Wed Sep 04, 2002 8:33 am
by Nargule
PingLeeQuan wrote:Hello... i ran intot he same thing a while back. I can assure you that using IP will not work for the simple fact that many corporations/ISPs..... use IP Address translation.
That's exactly what my concern is.
PingLeeQuan wrote:The best way is to use sessions in conjunction with Cookies. If Cookies is not an option, then you have to append the ID and Token of the sesison at the end of each link in your site.
I was hoping to avoid cookies. Appending the session ID and token at the end of each link was something I was hoping to avoid as well, but I guess that is what I'll do.

Tom

Posted: Wed Sep 04, 2002 9:11 am
by jason
Whats your reason to avoid using sessions and cookies? I use them everywhere without a problem.

Posted: Wed Sep 04, 2002 9:27 am
by Nargule
jason wrote:Whats your reason to avoid using sessions and cookies? I use them everywhere without a problem.
I was hoping to avoid cookies because some people don't like them and have them turned off.

As far as sessions go, I didn't say that I didn't want to use them, just that I didn't want to append the ID at the end of each link on my site.

After thinking about it further, I think I am just going to use cookies. Anyone who refuses to accept them will just have to deal with it.

Thanks all for your help,
Tom

Posted: Wed Sep 04, 2002 9:30 am
by jason
Looking at it practically, if a person isn't going to accept cookies (and the majority of people do, I don't know anyone personally who doesn't), they aren't going to give you their CC#.

Posted: Wed Sep 04, 2002 9:36 am
by Takuma
Using IP is a bad idea if a user is using a proxy server (if someone comes online with a same proxy what's gonna happen???). You can set sessions so that it will be saved on server, by doing that you can avoid using cookies. :wink:

Posted: Wed Sep 04, 2002 9:58 am
by Nargule
jason wrote:Looking at it practically, if a person isn't going to accept cookies (and the majority of people do, I don't know anyone personally who doesn't), they aren't going to give you their CC#.
Ok, I can't argue with that logic.

Tom

Posted: Wed Sep 04, 2002 10:02 am
by Nargule
Takuma wrote:Using IP is a bad idea if a user is using a proxy server (if someone comes online with a same proxy what's gonna happen???). You can set sessions so that it will be saved on server, by doing that you can avoid using cookies. :wink:
That is why I had concerns about using the IP address. The way I have it now works great when I play with it but it will crash and burn out in the real world.

Tom

Posted: Wed Sep 04, 2002 3:45 pm
by Takuma
Why don't you save the sessions in MySQL or in the server? It is possible...

Posted: Thu Sep 05, 2002 1:27 am
by Nargule
Takuma wrote:Why don't you save the sessions in MySQL or in the server? It is possible...
Ok, I guess I am missing something here. How can I save everything on the server? As it stand now, I am storing all the info in a mySQL db, but I need some kind of way of idenifying the client and that is what I need to store in a cookie (or append it to every link on my site), even if I use sessions. Do I have that right?

As you might have deduced, I am not familular with sessions, even after reading the links supplied above (which I read before even posting here).

Tom

Posted: Thu Sep 05, 2002 1:58 am
by gite_ashish
hi,

When using sessions, the details are stored on both sides - server and client.

On server side the details, default situations, are stored into flat files on the path specified by the "session.save_path" in php.ini. The default "session.save_handler" is files. It is possible to change this to MySQL... I think Takuma is talking about this only.

On client we can use persistant cookies... OR even of we don't use cookies explicitly, the Session functions use session (temporary) cookies for storing data on client side.

For each session web server & browser maintains an unique id... only this information gets transfered between client and server.

Posted: Thu Sep 05, 2002 2:30 am
by Nargule
gite_ashish wrote:hi,

For each session web server & browser maintains an unique id... only this information gets transfered between client and server.
Yea, that much I get. I just was confused about how the session ID got stored on the client.

I think the best thing for me to do now is write some short scripts that use sessions. I'm sure after I actually use them myself it will click and I'll be OK. I'll let you know how it goes.

Tom