Hello, I’m trying to mix PHP code with MT tags in order to check if a user is authenticated. The purpose is to show and hide published pages according to who is logged in.
We are using Movable Type 4.34 with: Community Pack 1.65, Enterprise Pack 1.31, Professional Pack 1.31
François Nonnenmacher on March 5, 2010, 4:39 a.m. Reply
Movable Type 4
Here is the code I use, it uses MT own session manager. First, define an “Authenticate” module template:
And then, on the first line of any page I want to protect, this code:
In this example, if the user has no active session, s/he is redirected to the login page then back to the secured page. You can add other conditions, such as
$session['can_post']
and other MT authorizations held in the session cookie.Note this solution only works if the page and the comment script are on the same domain, because it’s cookie-based (and the MT cookie can be set to be valid for an entire domain). You can’t share a cookie between different domains.
Movable Type 5
Here’s a different one that is supposed to work with MT5.1+ (I haven’t tested it yet):
Replace
http://localhost
with your domain name.Charlie Gorichanaz on October 26, 2013, 4:27 a.m. Reply
There is also an Endevver code sample (mt-php-MTUser) that is supposed to accomplish this goal with PHP more easily.