PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

Calling s2Member from external PHP

s2Member Plugin. A Membership plugin for WordPress®.

Calling s2Member from external PHP

Postby replaysMike » June 1st, 2011, 11:47 pm

Hey all,

Is it possible to call into s2Member's API functions or internal functions from an external PHP file?

I've got some files that I am unable to protect using the file_download_key/s2member_file_download method as they are SWF files that load other SWF files, and I can't control the absolute path from which they load. So they can't reside inside the s2member-files directory.

My plan was to simply create a wrapper PHP file which is already being passed a generated file_download_key, but I have no way to validate that key as I'm not sure which PHP files to include to access the library.

Help? :? Thanks!

Mike
User avatar
replaysMike
Registered User
Registered User
 
Posts: 3
Joined: June 1, 2011

Re: Calling s2Member from external PHP

Postby Cristián Lávaque » June 2nd, 2011, 1:23 pm

I'd probably start by searching something like http://www.google.com/search?q=use+word ... on+outside
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Calling s2Member from external PHP

Postby replaysMike » June 2nd, 2011, 4:02 pm

hey thanks! That's exactly what I was looking for. Now I just need to figure out how to validate that key in the s2Member code... for others here's what I did:

Code: Select all
   require_once("../../wp-load.php");
   get_header();
   echo "Custom PHP page outside of wordpress.<br/><br/>";
   echo "<p>".s2member_file_download_key('mydownloadfile.zip')."</p>";
   get_footer();
User avatar
replaysMike
Registered User
Registered User
 
Posts: 3
Joined: June 1, 2011

Re: Calling s2Member from external PHP

Postby replaysMike » June 2nd, 2011, 4:36 pm

ok I got it, here's how you validate a download key from outside of wordpress:

Code: Select all
   require_once("/wordpress_root_dir/wp-load.php");
   $download_key = $_GET["s2member_file_download_key"];

   if($download_key){
      echo "<p>Download key: $download_key</p>";
      
      $verified_key = c_ws_plugin__s2member_files::file_download_key ('Module1.html');
      $file_download_key_is_valid = $download_key === $verified_key;
      
      echo "<p>Verified key: $verified_key</p>";
   }else{
      // No download key provided
      $file_download_key_is_valid = false;
   }   

   if($file_download_key_is_valid)
      echo "Valid";
   else
      echo "Invalid";


In my case I hardcoded the filename as 'Module1.html', and only pass in the key which is also generated based on the same filename. Seems to work well.

Thanks Christian
Last edited by replaysMike on June 2nd, 2011, 8:46 pm, edited 1 time in total.
User avatar
replaysMike
Registered User
Registered User
 
Posts: 3
Joined: June 1, 2011

Re: Calling s2Member from external PHP

Postby Cristián Lávaque » June 2nd, 2011, 8:27 pm

Thank you for sharing that! I'm sure others will find it very helpful when they try to do something similar. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010


Return to s2Member Plugin

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests

cron