Wednesday, September 23, 2009

Godaddy reminder - Perl / CGI

cgi files must be file permission (via right click Filezilla (or other FTP program)) executable to work!!!

PHP that writes JS that empties SESSION cart into iframes

We wanted a "mini_cart" that could keep a visitor on our "satellite" products page until they'd investigated all products they might possibly want there.
The desired cart would then "dump" all these products into our more sophisticated home Java developed cart/shopping solution when the visitor is ready to checkout.

The solution involved using a PHP cart Class that saves into a user's SESSION,
appears only once they've chosen an initial product,
and disappears if they delete all items from their cart.

The cart appears on the page in the form of an AJAX populated Div.
That is, clicking "add to cart" calls the external Php class, adjusts the
cart in SESSION, and returns the current state to the page without refresh.

The final files needed are:
- The products page with "add to cart" buttons and an empty Div with an original ID
- PHP shopping cart class
- A "transfer cart" PHP script that writes some Javascript, and then turns the SESSION cart into Divs, loads each item into an iframe (also on our product page without refresh until everything is loaded) one by one so that the receiving application/mechanism adjust IT'S user cart accordingly, and then it forwards the visitor to their new cart.
- We will use Prototype for our AJAX for the most part, though a standard AJAX could just as easily be used and would suffice.

I'll post all the code as I get to it...
or you can contact me and I'll send you the code...

until then you can see the working sites here:

Perl Loop $_

#foreach loop and the $_ default variable

foreach my $element (@arraying) {
print $element . " ";

print "

foreach (@arraying) {
print $_ . "
"; #without setting a temporary variable, the default $_ is intrinsically set

Heredocs PHP


example 1:
$str = <<
Example of string
spanning multiple lines
using heredoc syntax.

example 2:
/* More complex example, with variables. */
class foo
var $foo;
var $bar;

function foo()
$this->foo = 'Foo';
$this->bar = array('Bar1', 'Bar2', 'Bar3');

$foo = new foo();
$name = 'MyName';

echo <<
My name is "$name". I am printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This should print a capital 'A': \x41

example 3:
echo <<<"FOOBAR"
Hello World!


as you can see, php $variables are printed via direct reference
and/or, as long as they're double quotation mark enclosed! awesome!