Options

Redirect Customers to Event Gallery From Your Site

mikegrbmikegrb Registered Users Posts: 9 Beginner grinner
I have a webpage at http://www.michaelgreb.com/prints.html that allows a customer to enter an "Event ID" or "Photo Shoot ID" to view proofs/purchase prints online. This form submits to a perl script on my web server which verifies that the id matches a SmugMug gallery of mine and then redirects the customer to the SmugMug gallery.
#!/usr/bin/perl

use strict;
use warnings;

use LWP::UserAgent;
use CGI qw /:standard/;

my $smugurl  = 'http://prints.michaelgreb.com';
my $formurl  = 'http://www.michaelgreb.com/prints.html';
my $cachedir = '/www/photog/cache';

if ( param('id') && checkid(param('id') )) {
        print redirect($smugurl . '/gallery/' . param('id'));
}
else {
        print redirect($formurl);
}

sub checkid {
        my $id = shift;
        return 1 if cachecheck($id);
        return 1 if smugcheck($id);
        return;
}

sub cachecheck {
        my $id = shift;
        return (-e "$cachedir/$id");
}

sub createcache {
        my $id = shift;
        open(F, ">$cachedir/$id") && close F;
}

sub smugcheck {
        my $id = shift;
        my $ua = LWP::UserAgent->new;
        $ua->max_redirect(0);
        my $response = $ua->head($smugurl . '/gallery/' . $id );
        if ($response->code == 200) {
                createcache($id);
                return 1;
        }
        return;
}

The three variables near the top need to be customized.
my $smugurl  = 'http://prints.michaelgreb.com';
my $formurl  = 'http://www.michaelgreb.com/prints.html';
my $cachedir = '/www/photog/cache';
The first, smugurl, is the url to your SmugMug gallery. The second, formurl, is the url for the form submitting to this script. If the id entered doesn't match a SmugMug gallery owned by you, the person gets redirected back to the form. The third, cachedir, is a directory on the web server that the web server has permission to write to. The first time someone enters a given url, the script checks SmugMug to see if it belongs to you. If so, it creates an empty file in this directory named with the gallery id. Upon subsequent requests for the same id, the script sees this file and sends the person on to SmugMug without having to check SmugMug first.

The HTML to use this script is simple, just a form that submits a single field, named 'id'. This is the HTML used for my form:
<form action="/prints.pl" method="post">
Event/Shoot ID:  <input type="text" name="id" / >
<input type="submit" value="Go" / >
</form>
Hopefully this will be useful to others out there. I, Michael Greb, the author of the above perl script release it into the public domain, do with it as you wish.

Comments

  • Options
    devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited March 5, 2007
    Mike,

    Nice work, it appears to work really well thumb.gif

    except if you enter something totally bogus like 'fred'. Should be a pretty easy fix.

    Cheers,

    David
    David Parry
    SmugMug API Developer
    My Photos
  • Options
    mikegrbmikegrb Registered Users Posts: 9 Beginner grinner
    edited March 5, 2007
    devbobo wrote:
    Mike,

    Nice work, it appears to work really well thumb.gif

    except if you enter something totally bogus like 'fred'. Should be a pretty easy fix.

    Cheers,

    David
    I didn't even concider trying text since invalid numeric entries resulted in the redirection to the smugmug homepage. All fixed.

    Simply change:
    if ( param('id') && checkid(param('id') )) {
    
    to:
    if ( param('id') && checkid(param('id')) && param('id') =~ /^\d+$/  ) {
    
    This ensures that the entered id is a number.
  • Options
    devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited March 5, 2007
    thumb.gif sweet
    David Parry
    SmugMug API Developer
    My Photos
  • Options
    sudermattsudermatt Registered Users Posts: 38 Big grins
    edited March 8, 2007
    My philosphy is, lots of design, ease of use, easy maintenance.

    I like to be able to tell people at the event what the url will be. For example, last weekend, My brother visited me and we played golf with this cool father & son. We were taking pictures and movies and stuff. So I told him, " give me a day or so to get the pictures uploaded, but go to sudermatt.com/ ", then I just made it up, " markgolfmarch07"

    sudermatt.com/markgolfmarch07

    to see how it works...try NewYears2005, or riverspicnic

    The point is, it can be anything.


    I'm an asp developer. I do it a little more "server side". On my website, if the url doesn't find a real page, I have a custom error page which evaluates what comes after my domain slash. I have a simple table where I set up the redirect.

    markgolfmarch07 -> sudermatt.smugmug.com/gallery/0233nnnn

    As long as I give people a unique name after the "/", I'm fine.

    I have a special page where I add new redirects so it takes only about 30 seconds to add new entries to the table.

    The intial setup is a bit of a pain...but once it's done...adding new galleries takes about one minute, and I don't have to change any html.

    If you want more details let me know. Here's what you will have to have:

    - webserver that works with IIS asp code
    - custom 400 error (page not found) page on the server
    - database
Sign In or Register to comment.