latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Protecting non-wordpress content

Home Forums Community Forum Protecting non-wordpress content

This topic contains 6 replies, has 3 voices. Last updated by  Jason (Lead Developer) 4 years, 10 months ago.

Topic Author Topic
Posted: Thursday Feb 16th, 2012 at 8:21 am #5358
Adam Tal
Username: baduist

I’ve built a web app in php+Javascript and I’m trying to set up s2member around it.

I have my main website at
example.com

Then s2member installed on a wordpress at
example.com/members

Then I have the actual app (which consists of one .php page) at:
example.com/app

I tried moving it to
example.com/members/app

and set the Login Welcome Page to a Special Redirection URL:
http://example.com/members/app

but it is still accessible to anyone, so I’m assuming s2member is using wordpress based functionality to protect pages rather than htaccess.

Is there a way to change it? I prefer to avoid using a wordpress page for this as it will complicate the way my php script works.

  • This topic was modified 4 years, 10 months ago by  Adam Tal.

List Of Topic Replies

Viewing 6 replies - 1 through 6 (of 6 total)
Author Replies
Author Replies
Posted: Thursday Feb 16th, 2012 at 4:25 pm #5403
Adam Tal
Username: baduist

[see update]

  • This reply was modified 4 years, 10 months ago by  Adam Tal.
Posted: Thursday Feb 16th, 2012 at 4:26 pm #5404
Adam Tal
Username: baduist

Ok seems to be easier that I thought. Sorry for the hasty post, there’s just so much to read ;)

What I did was use the conditional php tags like so:


require('../wp-blog-header.php'); // required so my app can tell if the wp user is even logged in.
if (current_user_can("access_s2member_level1")){ 
	// user is allowed to view, so do nothing.
} else {
   echo 'permission denied'; die(); // freeloaders no welcome - no app for you!:)
} 
	
<!-- the rest of my app code is here -->

I’d love to hear any comments or ideas for a more elegant way to do this.

  • This reply was modified 4 years, 10 months ago by  Adam Tal.
  • This reply was modified 4 years, 10 months ago by  Adam Tal.
Posted: Thursday Feb 16th, 2012 at 5:29 pm #5409
Eduan
Username: Eduan
Moderator

Hello Adam, thanks for the follow-up.

The only real advice I can offer is personal taste, I would only format the code a little different:

// required so my app can tell if the wp user is even logged in.
require('../wp-blog-header.php');
if (current_user_can("access_s2member_level1")) { 
	// user is allowed to view, so do nothing.
} else {
	// freeloaders no welcome - no app for you! :)
	echo 'permission denied'; die();
} 
	
/* the rest of my app code is here */

Haven’t tested it, but if it works for you then it’s OK. :)
Other than that. Well done! :)

Posted: Friday Feb 17th, 2012 at 3:14 am #5471
Adam Tal
Username: baduist

Not bad actually, much easier on the eyes that way. Thanks! :)

Posted: Friday Feb 17th, 2012 at 8:11 am #5478
Eduan
Username: Eduan
Moderator

You’re welcome. :)

Posted: Monday Feb 20th, 2012 at 4:44 pm #5724
Staff Member

If you’re loading your own content, you won’t actually need the templating functionality from WordPress, so you could use /wp-load.php instead, which is the standard way to handle this type of thing.

<?php
include_once "wp-load.php";
if (current_user_can("access_s2member_level1"))
	{ 
		// User is allowed to view, so display something here.
	}
else
	exit("Permission denied!");
?>
Viewing 6 replies - 1 through 6 (of 6 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.