Flag a node programatically
Try below code... You can read node arguments using arg function in Drupal...

global $user;
$flag = flag_get_flag('purchase');
$node = node_load(arg(1));
$flag-&gt;flag('purchase', $node-&gt;nid, user_load($user-&gt;uid), TRUE);