Shopping Cart
Moderator: General Moderators
Shopping Cart
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
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
- gite_ashish
- Forum Contributor
- Posts: 118
- Joined: Sat Aug 31, 2002 11:38 am
- Location: India
hi,
The best & reliable way is to use sessions.
See PHP manual:
http://www.php.net/manual/en/ref.session.php
You also need to add (registation,) login scripts into ur shopping cart.
What other ways are there to uniquely identify a client?
The best & reliable way is to use sessions.
See PHP manual:
You also need to add (registation,) login scripts into ur shopping cart.
- gite_ashish
- Forum Contributor
- Posts: 118
- Joined: Sat Aug 31, 2002 11:38 am
- Location: India
hi,
See this for retaining 0:
See PHP man:
http://www.php.net/manual/en/function.number-format.php
http://www.php.net/manual/en/function.sprintf.php
regards,
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:
regards,
-
PingLeeQuan
- Forum Commoner
- Posts: 58
- Joined: Tue Sep 03, 2002 8:08 am
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.
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.
That's exactly what my concern is.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.
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.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.
Tom
I was hoping to avoid cookies because some people don't like them and have them turned off.jason wrote:Whats your reason to avoid using sessions and cookies? I use them everywhere without a problem.
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
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.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.
Tom
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?Takuma wrote:Why don't you save the sessions in MySQL or in the server? It is possible...
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
- gite_ashish
- Forum Contributor
- Posts: 118
- Joined: Sat Aug 31, 2002 11:38 am
- Location: India
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.
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.
Yea, that much I get. I just was confused about how the session ID got stored on the client.gite_ashish wrote:hi,
For each session web server & browser maintains an unique id... only this information gets transfered between client and server.
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