Fork me on GitHub

Module hack or new development?  Bottom

  • I have a challenge for all you aspiring module developers out there.

    I have a custom PN module we call pnlists (viral listbuilding) that assigns all members an affiliate ID like:

    http://domain.com/index.php?module=pnlists&affiliateID=1

    Currently, to make it vastly easier for people to actually USE their affiliate ID, I create (manually) subdomains that re-direct to this nasty affiliate ID.

    So that members can use http://handle.domain.com instead.

    If anyone has an idea on how to automate this procedure (I'm facing an influx of 1000 members a month to one of my sites), I'd greatly appreciate it! :)

    Steve
  • I know it isn't what you are looking for, but I would make your pnlists module put a link in the persons 'You Account' page that linked to the correct affiliateID. Then when the user logged in they would just go to their 'Your Account' page and click on the link which would automatically take them to the right page. Then you wouldn't need to do any extra work when new affiliates are created and you don't need any fancy re-write rules, etc that would need to be processed for every user.

    Granted it isn't quite as convenient for your end users.

    -Chris
  • Quote

    I would make your pnlists module put a link in the persons 'You Account' page that linked to the correct affiliateID

    I have no idea what this would accomplish. What I need is a URL completely external to the site

    such as

    name.sitename.com

    that accomplishes the same thing as the above really nasty looking URL using mod-re-write, so that nobody is left trying to promote the site with that ugly mess. and everyone will be able to even pass their affiliate URL over the PHONE, it will be so simple.

    :)
  • Ok, this idea intrigued me enough to play with it for a while. The problem is that I don't know for sure exactly what it is you are looking for, but assuming all you want is for http://handle.domain.com to be directed to
    http://handle.domain.com/index.php?module=pnlists&affiliateID=1 and NOT http://handle.domain.com/index.php?module=PNphpBB2 or any other URL besides the base file with no query string. And if they enter http://www.domain.com that it goes to your normal start page, etc. Then the following should work.

    The easiest way that I could find to do this which would require no URL rewrites, or additional work on your part would be to do the following.

    In your pnlists module in the file pnuserapi.php you would need to create a function that returns the ID number that corresponds to a given 'handle'. For an example I would create the function pnlists_userapi_getAffiliateID() and put it in /modules/pnlists/pnuserapi.php. The purpose of this function would be to take a string input 'handle' and figure out what the corresponding affilliateID was. I assume you have some table in your database that maps affiliateID numbers to the handle that you have given the person. pnlists_userapi_getAffiliateID() takes as an argument the 'handle' from handle.domain.com and returns the appropriate ID number.

    Then in your main index.php file (core file in the PostNuke directory) I would add the following code:

    Code

    list($affiliate,$server,$domain) = explode('.',$_SERVER{'HTTP_HOST'});

    if ((strtolower($affiliate) != 'www') && empty($_SERVER{'QUERY_STRING'})) {
        if (pnModAPILoad('pnlists','user')) {
            $_REQUEST{'affiliateID'} = pnModAPIFunc('pnlists','user','getAffiliateID',array('handle'=>$affiliate));
            $module = 'pnlists';
            $func = 'main';
        }
    }


    I would add it right after this code:

    Code

    // Get variables
    list($module,
         $func,
         $op,
         $name,
         $file,
         $type) = pnVarCleanFromInput('module',
                                      'func',
                                      'op',
                                      'name',
                                      'file',
                                      'type');


    Then if anyone goes to http://pawmarks.yourdomain.com/ the server will bring up the page:

    http://pawmarks.yourdomain.com/index.php?module=pnlists&affiliateID=XYZ where XYZ is the affiliateID for pawmarks.

    If they go to http://pawmarks.yourdomain.com/index.php?module=PNphpBB2 then it will take them to the forums just like it would normally.

    This is assuming your pnlists code uses pnVarCleanFromInput('affiliateID') to get the affiliateID from the system.
    This also assumes that your DNS server is set to route *.yourdomain.com to your server.

    Hope that helps.
    If it doesn't then you will need to describe exactly what it is you want a little better.

    -Chris
  • One additional change. The code in my previous post will run into a problem if the handle doesn't have a valid affiliateID. This code fixes that problem.

    Code

    list($affiliate,$server,$domain) = explode('.',$_SERVER{'HTTP_HOST'});

    if ((strtolower($affiliate) != 'www') && empty($_SERVER{'QUERY_STRING'})) {
        if (pnModAPILoad('pnlists','user')) {
            $affiliateID = pnModAPIFunc('pnlists','user','getAffiliateID',array('handle'=>$affiliate));
            if ($affiliateID) {
                $_REQUEST{'affiliateID'} = $affiliateID;
                $module = 'pnlists';
                $func = 'main';
            }
        }
    }


    Your pnlists_userapi_getAffiliateID() function should return false if there isn't a valid affiliateID for the given handle.

    -Chris

This list is based on users active over the last 60 minutes.