PHP Auth in Movable Type


/ Published in: PHP
Save to your folder(s)

Credit goes to François Nonnenmacher.


Copy this code and paste it in your HTML
  1. <?php
  2. $ch = curl_init();
  3. curl_setopt($ch, CURLOPT_URL, "<$mt:AdminCGIPath$><$mt:CommentScript$>?__mode=session_js&blog_id=<mt:BlogID>&jsonp=mtSetUserOrLogin");
  4. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  5. curl_setopt($ch, CURLOPT_COOKIE, $_SERVER["HTTP_COOKIE"]);
  6. $json = curl_exec($ch) or die("Cannot connect to MT!");
  7. curl_close($ch);
  8. $json = substr($json, 17, strlen($json)-20);
  9. $session = json_decode($json, true);
  10. if ($session['can_comment'] == 0) {
  11. header("Location: <$mt:AdminCGIPath$><$mt:CommentScript$>?__mode=login&blog_id=<mt:BlogID>&return_url=".rawurlencode($_SERVER["REQUEST_URI"]));
  12. }
  13. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.