Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

How to have payed Members only pages?

Go to End

3 Posts   1735 Views


Community Member, 89 Posts

31 January 2010 at 11:49pm

I'm really excited about using SilverStripe for my web development projects, but I have one site though which I'm not sure how easy it would be to accomplish in SS.

It is an educational website, where you have to pay a yearly/monthly fee to view most of the pages.

The main aspect I am worried about is how to deal with "members" in SilverStripe. I need the ability:

- for members to register and pay and have immediate access to members only pages
- need to be able to have different categories of membership, some will get it cheaper, some for free etc

Can someone please point me in the right direction for how I could accomplish this in SilverStripe? Is it possible without too much extra coding?

Many Thanks!


Community Member, 42 Posts

5 February 2010 at 4:09pm

Edited: 05/02/2010 4:10pm


Sure you can do this with SS.

- First create a registration form (we will need to create the logic to connect to a online payment gateway, or use payment module).

- Once you sorted payment, you need to create a new member and save it into a group (you can create different groups).

function registerAction($data,$form) { //you call this function when user submit registation form (or after you check payment)
		$member=DataObject::get_one('Member',"Email = '" . mysql_real_escape_string($data['Email']) . "'"); //check if the email is in the DB already
		if(!$member) { // if email is not in DB create a new member
			$member = new Member();
			$form->saveInto($member); //insert new member value from the form
			$member->RegistrationHash = md5(uniqid(rand(), true));
			$member->write(); //save new member

- Add a check box to your pages so you can choose if the page is members only.

function getCMSFields() {
	  	$fields = parent::getCMSFields();
                $fields->addFieldToTab("Root.Content.Main", new CheckboxField('MemberOnly', 'For member only?'), 'Content');

- create a function in Page.php to check if the page is members only and check if the visitor is logged in.

function canView($member = null) {	// this function gets called when you load the page.
		if($this->MemberOnly) {
			$member = Member::currentUser();
			if (!$member) return false;
		return parent::canView($member);


Community Member, 89 Posts

6 February 2010 at 2:21am

Amazing! I shall give this a go, thank you very much!