Hints for/Help with Order API and custom CGI

This is an archive of old posting to the User Forum

Hints for/Help with Order API and custom CGI

Postby Guest » Fri Nov 22, 2002 5:22 pm

I'm wondering if anyone out there has some experience with utilizing
the custom CGI option that is available with the Pro version of
ShopSite (mine is 6.1). I've been running through several different
methods to try and get the functionality that I want but I seem to be
handling this incorrectly.

At the moment I would like to forward (via POST method) the
information that is output to the custom CGI along to a second PHP
script that will handle the data for me (deal with a PHP session
etc.). I was planning on using some sort of redirect mechansim in my
custom CGI but it seems that the PHP script is simply launched from
within the thankyou.cgi - the same way that the custom CGI is launched
- the page remains "thankyou.cgi" rather than forwarding.

It may be conceivable to write a CGI that does what I need it to but I
would like to simplify things by continuing my PHP session and
handling things from there.

I can spew details about this but I just want to start by asking if
anyone that keeps an eye on these newsgroups has used this function or
would have any helpful input, especially in regards to utilizing PHP
with this option. I have been running into all sorts of problems
trying to get my PHP scripts/pages working with the Order API/custom
CGI.

Thanks much.

Eric Gehner
Guest
 

Re: Hints for/Help with Order API and custom CGI

Postby Phil » Fri Nov 22, 2002 7:54 pm

Hi Eric,

Try the software kids.
james@softwarekids.com

James made some really nice programs for my shopsite website and we have
some more programs we're going to do.

Phil


eric@growprospects.com wrote:

I'm wondering if anyone out there has some experience with utilizing
the custom CGI option that is available with the Pro version of
ShopSite (mine is 6.1). I've been running through several different
methods to try and get the functionality that I want but I seem to be
handling this incorrectly.

At the moment I would like to forward (via POST method) the
information that is output to the custom CGI along to a second PHP
script that will handle the data for me (deal with a PHP session
etc.). I was planning on using some sort of redirect mechansim in my
custom CGI but it seems that the PHP script is simply launched from
within the thankyou.cgi - the same way that the custom CGI is launched
- the page remains "thankyou.cgi" rather than forwarding.

It may be conceivable to write a CGI that does what I need it to but I
would like to simplify things by continuing my PHP session and
handling things from there.

I can spew details about this but I just want to start by asking if
anyone that keeps an eye on these newsgroups has used this function or
would have any helpful input, especially in regards to utilizing PHP
with this option. I have been running into all sorts of problems
trying to get my PHP scripts/pages working with the Order API/custom
CGI.

Thanks much.

Eric Gehner
Phil
 

Re: Hints for/Help with Order API and custom CGI

Postby Rob » Fri Nov 22, 2002 10:55 pm

2 options:

Option 1: Set a redirect URL in a perl cgi script that redirects the user to
your PHP page, and send the details you need the PHP script to have encoded
into the URL. This way, you get to run your PHP script from the web, which
works nice with sessions. For example:
print "Location: /cgi-bin/sc/script.php?name=john&total=5...\n\n";

Option 2:
Make it run as a command line PHP program. That is, the first line of the
PHP script should be:
#!/usr/local/bin/php
or wherever you have a binary compiled PHP script that can run files on the
server. This will run your PHP script locally, but I am not sure how it will
handle sessions running locally instead of from the web directly.

Hope that helps.

Rob

<eric@growprospects.com> wrote in message
news:3DDEBC25.C5D124EF@growprospects.com...
I'm wondering if anyone out there has some experience with utilizing
the custom CGI option that is available with the Pro version of
ShopSite (mine is 6.1). I've been running through several different
methods to try and get the functionality that I want but I seem to be
handling this incorrectly.

At the moment I would like to forward (via POST method) the
information that is output to the custom CGI along to a second PHP
script that will handle the data for me (deal with a PHP session
etc.). I was planning on using some sort of redirect mechansim in my
custom CGI but it seems that the PHP script is simply launched from
within the thankyou.cgi - the same way that the custom CGI is launched
- the page remains "thankyou.cgi" rather than forwarding.

It may be conceivable to write a CGI that does what I need it to but I
would like to simplify things by continuing my PHP session and
handling things from there.

I can spew details about this but I just want to start by asking if
anyone that keeps an eye on these newsgroups has used this function or
would have any helpful input, especially in regards to utilizing PHP
with this option. I have been running into all sorts of problems
trying to get my PHP scripts/pages working with the Order API/custom
CGI.
Rob
 

Re: Hints for/Help with Order API and custom CGI

Postby Eric Gehner » Sat Nov 23, 2002 4:12 am

Rob,
(-->reposted with some corrections<--eg)

Thanks so much for your response. I was wondering if you might be able to shed a
little more light if I told you the methods I've already attempted. I've used
both the methods you describe below but I believe that Option 1 is going to be
the eventual solution - with a bit more work. Any thoughts on the following
would be helpful.

I've abandoned Option 2 because my testing seems to indicate that when the PHP
script is run from the command line the current session isn't picked up, rather
a new session is created.

Option 1 also has it's problems, largely because the method that the
thankyou.cgi uses or calls the custom CGI seems a bit odd. Any redirects I've
attempted using seem to result in the second script being executed within the
thankyou.cgi rather than leaving thankyou.cgi and being taken to the script that
is indicated in the redirection. This happens whether it is a perl CGI or a php
script (for php scripts, the location in or out of the cgi-bin seems
irrelevant). The thankyou.cgi seems to be a bit of a mystery as to how it
operates.

I've used a perl script as simple as:

---begin code---
#!/usr/bin/perl -w
print "Content-type: text/html\n\n";

print "Location: http://www.anotherlocation.com/index.php\n\n";
---end code---

or using CGI.pm...

---begin code---
#!/usr/bin/perl -w
print "Content-type: text/html\n\n";

use CGI;
$query=new CGI;
print $query->redirect('http://www.anotherlocation.com/index.php');
---end code---

My work so far indicates that in order for a custom cgi to be run it must
include a content-type header. However, any following information involving a
redirect seems to simply be printed to the page rather than handled(parsed?) by
the browser. Perhaps my ignorance of Perl is blinding me to something obvious.
The code below actually made me a bit optimistic by returning the results of the
PHP code that is POSTed to at the bottom of this script. Sadly, this all
remained within the thankyou.cgi and all the headers appeared along with the
result of the parsed code (which was simply printing all the POST
information/variables as expected). The other drawback is that this php page
runs within the thankyou.cgi and does not pick up the current session but
creates a new one. Not what I'm looking for. I'm a bit flustered as to how to
move along POST information and get out of the thankyou.cgi so that I can pick
up my PHP session. (there's a bit more info after this code...)

---begin code---
#!/usr/bin/perl -w
print "Content-type: text/html\n\n";

use LWP::UserAgent;
use HTTP::Request::Common qw(POST);

if ($ENV{'REQUEST_METHOD'} =~ /get/i) {
$buffer = $ENV{'QUERY_STRING'};
$method = "Get";
}
else {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
$method = "Post";
}

@nvpairs = split(/&/, $buffer);
foreach $pair (@nvpairs)
{
($name, $value) = split(/=/, $pair);

$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$form_ref .= "$name => $value, ";
}

$ua = LWP::UserAgent->new;

$req = POST 'http://www.anotherlocation.com/work_with_post_info.php',
[$form_ref];

$res = $ua->request($req);
print $res->as_string;
---end code---

Using a meta refresh does work to get out of the thankyou.cgi but it seems like
a rather clumsy way to go about doing things and I still want to pass along some
information by POST and probably a back up using GET as you suggest. Is this the
only way I'm going to be able to get out of thankyou.cgi and run my PHP script
to pick up the current session?

---begin code---
#!/usr/bin/perl -w
print "Content-type: text/html\n\n";
print "<META HTTP-EQUIV='refresh' CONTENT='7;
URL=http://www.anotherlocation.com'>";
---end code---

My other idea was to use my custom cgi to create a custom receipt page and allow
users to click on a link to continue the process to get their digital goods.
This will require that some of the previously POSTed info exists in the HTML for
re-POST via form. I just wanted to make the information transfer as transparent
as possible, but I suppose I'm not sending anything extremely sensitive. If you
have any other suggestions or reasons why my perl script wouldn't be working,
please let me know.

Sorry this was so verbose.

Eric



Rob wrote:

2 options:

Option 1: Set a redirect URL in a perl cgi script that redirects the user to
your PHP page, and send the details you need the PHP script to have encoded
into the URL. This way, you get to run your PHP script from the web, which
works nice with sessions. For example:
print "Location: /cgi-bin/sc/script.php?name=john&total=5...\n\n";

Option 2:
Make it run as a command line PHP program. That is, the first line of the
PHP script should be:
#!/usr/local/bin/php
or wherever you have a binary compiled PHP script that can run files on the
server. This will run your PHP script locally, but I am not sure how it will
handle sessions running locally instead of from the web directly.

Hope that helps.

Rob

<eric@growprospects.com> wrote in message
news:3DDEBC25.C5D124EF@growprospects.com...
I'm wondering if anyone out there has some experience with utilizing
the custom CGI option that is available with the Pro version of
ShopSite (mine is 6.1). I've been running through several different
methods to try and get the functionality that I want but I seem to be
handling this incorrectly.

At the moment I would like to forward (via POST method) the
information that is output to the custom CGI along to a second PHP
script that will handle the data for me (deal with a PHP session
etc.). I was planning on using some sort of redirect mechansim in my
custom CGI but it seems that the PHP script is simply launched from
within the thankyou.cgi - the same way that the custom CGI is launched
- the page remains "thankyou.cgi" rather than forwarding.

It may be conceivable to write a CGI that does what I need it to but I
would like to simplify things by continuing my PHP session and
handling things from there.

I can spew details about this but I just want to start by asking if
anyone that keeps an eye on these newsgroups has used this function or
would have any helpful input, especially in regards to utilizing PHP
with this option. I have been running into all sorts of problems
trying to get my PHP scripts/pages working with the Order API/custom
CGI.
Eric Gehner
 

Re: Hints for/Help with Order API and custom CGI

Postby Rob » Sat Nov 23, 2002 9:24 am

Well, option 1 does seem the way to go for your sessions. First thing I
would do is not have Shopsite return the receipt, as this will cause your
custom CGI to run in the webpage that thankyou.cgi generates.

Next, I would parse out all the data, and then *only* print something like:
print "Location:
https://www.your_domain.com/script.php? ... $product...\n\n";
exit;

Do not print a Content-type header, as this will invalidate the Location:
redirect.

This way you can redirect the user seamlessly to your php script, and pass
the needed data in the url. Then have your php script output a receipt if
you want, and continue on with your process. If you're worried about
personal information in the URL, use a simple encryption alogorithm on the
data being passed in the URL, name the variables randomly, and decode it in
the php script.

This should work if you are willing to live with passing data via the URL
and not having Shopsite output the receipt page.

Rob

"Eric Gehner" <eric@growprospects.com> wrote in message
news:3DDF5479.A0AC9D60@growprospects.com...
Rob,
(-->reposted with some corrections<--eg)

Thanks so much for your response. I was wondering if you might be able to
shed a
little more light if I told you the methods I've already attempted. I've
used
both the methods you describe below but I believe that Option 1 is going
to be
the eventual solution - with a bit more work. Any thoughts on the
following
would be helpful.
Rob
 


Return to User Forum Archive

Who is online

Users browsing this forum: No registered users and 15 guests