Is this an effective way to do revenue sharing

Discussion in 'PHP' started by fordP, Dec 30, 2006.

  1. #1
    Give me your thoughts as to whether this is an effective revenue sharing model

    	// check to make sure this is a full story
    	if (strcasecmp(pagename, "story") != 0){
    		// not a full story, no adsense sharing
    		$tpl->assign($params['assign'], 0);
    		return;
    	}
    	
    	// check to see if the author has an adsense id on their profile
    	if ($tpl->get_template_vars("google_adsense_id") == ""){
    		// this author hasn't provided their adsense id, no sharing
    		$tpl->assign($params['assign'], 0);
    		return;
    	}
    	
    	// make sure the logged in user isn't the same user who submitted the story
    	// using a case insensitive compare because the user name isn't case sensitive
    	if (strcasecmp($tpl->get_template_vars("user_logged_in"), $tpl->get_template_vars("share_revenue_submitter")) == 0){
    		// the user viewing the story is also the author, can't show them their own ads, no sharing
    		$tpl->assign($params['assign'], 0);
    		return;
    	}
    
    	// generate a random number between 1 and 100
    	srand((float) microtime() * 10000000);
    	$random = rand(1, 100);
    
    	// check the random number against their adsense percent (defaults to 50% but can be adjusted)	
    	if ($random > $tpl->get_template_vars("google_adsense_percent")){
    		// if the random number is higher than their percent of revenue sharing, no sharing this time
    		$tpl->assign($params['assign'], 0);
    		return;
    	}
    
    	// passed all checks, use the users adsense ID for this page	
    	$tpl->assign($params['assign'], 1);
    	return;
    }
    Code (markup):

     
    fordP, Dec 30, 2006 IP
  2. GeorgeB.

    GeorgeB. Notable Member

    Messages:
    5,695
    Likes Received:
    288
    Best Answers:
    0
    Trophy Points:
    280
    #2
    Looks clean and focused. I can easily follow the logic and it checks for everything I'd check for.

    The thing is the question of surrounding circumstances arises. It really depends on the environment you plan to deploy this in. I can't really make the call because I don't know the whole story and you may very well be missing a check or security measure.

    But in general it looks sound.
     
    GeorgeB., Dec 31, 2006 IP
  3. streety

    streety Peon

    Messages:
    321
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I would suggest using mt_rand rather than rand but I can't see any problems and the choice of rand function isn't exactly crucial.

    Looks good.
     
    streety, Jan 1, 2007 IP