Forum Index Search Forum Register Log in

Runs on XP to Win 10

Current

Download 7.0

Download 7.1 Beta5 upgrade



A donation makes a contribution towards the time and effort that's going in to running this site.

Steffen

Contact:
My mail address is
at the top of the paypal form :

Your donations will help to keep this site alive and well.


Update your links !! November 2016 the forum is at www.apachelounge.com/sambar

In the forum there are links to sambarserver.info,
replace "sambarserver.info" with "apachelounge.com/sambar"
trying to build a shopping site to run on sambar

 
Post new topic   Reply to topic    Sambar Forum Index -> Coding & Script Corner
View previous topic :: View next topic  
Author Message
julian



Joined: 14 Feb 2005
Posts: 11
Location: UK

PostPosted: Tue 01 Mar '05 15:19    Post subject: trying to build a shopping site to run on sambar Reply with quote

Hi, thanks for your previous help! I have now given up trying to install Agora to run on a windows box, so most of my earlier problems are moot.

I am now trying to build a basic shopping cart myself, to run on Sambar 6.01 on a windows 2000 box. Its going ok but I have hit a snag with perl. any help would be much appreciated!!!

I want the script to find out if a customer basket file already exists, the code I am trying is copied below, but the test: if ($files{$isafile}){ etc is always false.

I'm stumped if I can figure out why, (but then I'm a pretty crap programer!)

# open the basket directory and read it in, put it in @files
opendir(DIR, "./baskets");

while($name = readdir(DIR)){
push(@files, $name);
}
close(DIR);

# check to see if the customer has a basket
if ($files{$isafile}){
# if so use it
$new = 0;
} else {
# if not make one
$new = 1;
$nextfile = $FORM{customerid};
$nextfile .= $FORM{username};
$nextfile .= ".html";
open(OUT, ">baskets/$nextfile");
}

if ($new == 1){
&write_new_html_header;
&write_lines_of_product_choice;
&end_table_checkout_button;
} else {
&copy_existing_basket;
}

Much appreciate any help!!!!
Back to top
View user's profile
julian



Joined: 14 Feb 2005
Posts: 11
Location: UK

PostPosted: Tue 01 Mar '05 19:22    Post subject: Reply with quote

Just got it with

if (-e "baskets/$isafile"){

much simpler ....

Sorry to bother you

Julian
Back to top
View user's profile
cryptor3



Joined: 13 Jun 2004
Posts: 101
Location: kah-li-forn-yah

PostPosted: Tue 01 Mar '05 19:26    Post subject: Reply with quote

Here's my suggestion. It's not necessary to do the readdir step, because you can just use the -e flag (exists) to test whether a file exists. I tried to reproduce your logic, but some of it may not be as you intended since I don't know what comes before or after this snippet.

Code:
# TODO: you need to untaint this input.  (Security risk)
$customerfile = $FORM{customerid} . $FORM{username} . ".html";

if (-e './baskets/' . $customerfilename) {

&copy_existing_basket;

} else {
open(OUT, ">baskets/$customerfile");
&write_new_html_header;
&write_lines_of_product_choice;
&end_table_checkout_button;

}

As a side note, I'd say that if you're going to use this as a production system, you are most likely going to run into problems unless you think very hard about concurrency issues. But building a shopping systemwill most likely provide you with some good experience. I tried to build a shopping system once. It failed because the guy who wanted it didn't want to pay me. A shopping system is probably something where you'll want some peer review.

You also have to think about system security. And when I say think about security, this is one of the highest forms of outside-the-box thinking: boundary conditions, malformed input, inputs from way out in left field. (The "untainting" todo is part of this area.) Once you've wrapped your head around the code I've presented here, I can show you how to untaint, and what it means to untaint.

Also, good system design is important. Personally I wouldn't use .html files to store the baskets directly. Number one, for efficiency reasons, and number two, for privacy reasons (my guess is that you just link directly to the baskets directory to display). One of the main tenets of good design is to separate presentation (showing the basket) from content (storing the data of the basket). This will allow your system to be extensible, and upgradeable, especially if you don't like the look of it.
Back to top
View user's profile
waldbauer.com



Joined: 08 Jun 2004
Posts: 105
Location: Vienna

PostPosted: Wed 02 Mar '05 9:19    Post subject: Reply with quote

There are many open source php shopping systems available. We use a very basic php shopping cart which has been modified after months to our needs. Now it works perfect.

Try to get the simpliest php/mysql shopping cart system and make experience with changing the code. You will have more fun when you know whats going on within the script.
Back to top
View user's profile Visit poster's website
mark45



Joined: 15 Feb 2017
Posts: 1

PostPosted: Wed 15 Feb '17 12:53    Post subject: Re: trying to build a shopping site to run on sambar Reply with quote

julian wrote:
Hi, thanks for your previous help! I have now given up trying to install Agora to run on a windows box, so most of my earlier problems are moot.

I am now trying to build a basic ebay alternative cart myself, to run on Sambar 6.01 on a windows 2000 box. Its going ok but I have hit a snag with perl. any help would be much appreciated!!!

I want the script to find out if a customer basket file already exists, the code I am trying is copied below, but the test: if ($files{$isafile}){ etc is always false.

I'm stumped if I can figure out why, (but then I'm a pretty crap programer!)

# open the basket directory and read it in, put it in @files
opendir(DIR, "./baskets");

while($name = readdir(DIR)){
push(@files, $name);
}
close(DIR);

# check to see if the customer has a basket
if ($files{$isafile}){
# if so use it
$new = 0;
} else {
# if not make one
$new = 1;
$nextfile = $FORM{customerid};
$nextfile .= $FORM{username};
$nextfile .= ".html";
open(OUT, ">baskets/$nextfile");
}

if ($new == 1){
&write_new_html_header;
&write_lines_of_product_choice;
&end_table_checkout_button;
} else {
&copy_existing_basket;
}

Much appreciate any help!!!!


Hello,
I got the problem while compiling code .
Back to top
View user's profile

Post new topic   Reply to topic    Sambar Forum Index -> Coding & Script Corner
Page 1 of 1