KBD

Keith Devens .com

Thursday, March 18, 2010 Flag waving
Would that which we have achieved have been possible if Providence had not helped us? – Adolf Hitler (in a speech at Regensburg on June 6th, 1937)
← Testing non-CMS site administrationAugust 6, 2001 PDB →

Daily link icon Saturday, April 10, 2004

lazyweb: Movable Type question (how to do an "Edit this Page" button)

How does Movable Type know when you're logged in? I'd like to modify a friend's blog so that when he's logged in, a little edit button shows up next to each of his Movable Type posts so that he can go right to the MT interface to edit it. His static pages are parsed by PHP, so I can put programming in them. I just need to know how Movable Type knows he's logged in so I can mimic that.

Update: I poked around the source for some minutes, and after getting to some parts where it left cookies I figured I'd just take a look at what cookies Movable Type leaves around when you're logged in. I should have just done that in the first place.

I created a simple PHP script:

<?php
header
("Content-type: text/plain");
print_r($_COOKIE);
?>

And once I discovered, like Dennis pointed out in a comment, that MT leaves a "user" cookie, I just added the following simple code to his main index template right after where his post title is displayed.

<?php
if(isset($_COOKIE['user'])){?>
    <a href="/weblog/mt.cgi?__mode=view
&_type=entry&id=<$MTEntryID$>&blog_id=<$MTBlogID$>">(edit)</a>
<?php ?>

It's really simple logic, and it doesn't test to see if you're really logged into Movable Type or whether there just happens to be a "user" cookie lying around. But, it's good enough, and if for some strange reason my simple code thinks he's logged in when he's not, the link will just go to the Movable Type login page and no harm done.

Note, I split up the URL above so that it doesn't bust out my page layout.

Update (4/13): Edited the title to better reflect its content.

← Testing non-CMS site administrationAugust 6, 2001 PDB →

Comments XML gif

Dennis Pallett (http://www.nocertainty.com) wrote:

The 'user' cookie contains the MT login information, so I guess that's a start. You might want to dig around the MT files, and try finding the authentication mechanism to reverse-engineer it. Or you could search the support forums, to see if anyone else has tried this.

∴ Dennis Pallett | 10-Apr-2004 3:38pm est | http://www.nocertainty.com | #4344

Keith (http://keithdevens.com/) wrote:

Thanks Dennis. I poked around the source for a while trying to figure out how it did everything. After some minutes, I just decided to look and see if MT left any cookies indicating that a user was logged in, and they do. I'm about to post an explanation of what I did.

Keith | 10-Apr-2004 3:48pm est | http://keithdevens.com/ | #4345

Sparticus (http://iamsparticus.co.uk) wrote:

If you're using Firefox (which I guess you are) then you can either download the webdeveloper extension, which'll tell you all the cookies set by a page, or you can look in tools -> options -> privacy -> cookies and search for cookies left by the site that look suspicious.

∴ Sparticus | 13-Apr-2004 7:38pm est | http://iamsparticus.co.uk | #4361

Sparticus (http://iamsparticus.co.uk) wrote:

Oh and to make it more portable you might want to change the '/weblog/mt.cgi' of the a href attribute to '&lt;$MTCGIPath$&gt;mt.cgi'.
That'll work for all installations of MT, regardless of where MT's installed too.

∴ Sparticus | 20-Apr-2004 7:35am est | http://iamsparticus.co.uk | #4386

Keith (http://keithdevens.com/) wrote:

Ooh, neat. Thanks, I hadn't thought of that.

Keith | 20-Apr-2004 1:08pm est | http://keithdevens.com/ | #4388

Julien Couvreur (Dumky) (http://blog.monstuff.com) wrote:

You could switch from a server-side detection of the "user" cookie to a client-side one...
This way you can still serve completely static html with MovableType, in exchange for requiring javascript on the client and a couple lines of javascript to parse the document.cookie data.

∴ Julien Couvreur (Dumky) | 5-May-2004 5:55pm est | http://blog.monstuff.com | #4507

Mikey H (http://www.mediajunk.com/public/) wrote:

Thanks for that ... but ... does anyone know where I can find a button that I can add to my web browser bar to edit an MT page?

Many thanks,
-- M

∴ Mikey H | 3-Nov-2004 11:02am est | http://www.mediajunk.com/public/ | #6209

Keith (http://keithdevens.com/) wrote:

You could probably do something with a Javascript bookmarklet that would bring you to Movable Type's edit screen for the current page. I don't now have time to figure out how that would be done, but I'm confident it wouldn't be very hard.

Keith | 4-Nov-2004 1:29am est | http://keithdevens.com/ | #6229

timtak (http://eigodaigaku.com) wrote:

Nice.

But I don't seem to have been able to get it to work.
Perhaps I am not parsing the page. I have added an .htaccess that tells my sever to parse the page.

My ISP, ipowerweb.com seems to have recently prevented my ftp client from seeing files which start with a dot. I am downloading the free ftp client you recommend (smartftp).

Tim

∴ timtak | 10-Nov-2004 6:36pm est | http://eigodaigaku.com | #6332

timtak (http://eigodaigaku.com) wrote:

Dear Keith

I added some echo's to the code, and the "hello" is displayed, but the "we are in" is not.

Any suggestions?

Thanks...

<?php
echo "hello";
if(isset($_COOKIE['user'])){echo "we are in"; ?>
<a href="http://blogurl.com/cgi-bin/mt.cgi?
_mode=view&_type=entry&id=<>&blog_id=<MTBlogID$>">(edit)</a>
<?php } ?>

Tim

(I brok the URL too, to stop it messing up your site layout)

∴ timtak | 10-Nov-2004 10:56pm est | http://eigodaigaku.com | #6333

Keith (http://keithdevens.com/) wrote:

Um, maybe you're not logged in?

Keith | 10-Nov-2004 11:23pm est | http://keithdevens.com/ | #6334

219.127.61.37 wrote:

Hmm..perhaps you are right. My blog does not seem to be responding right now. But I could have sworn that I was logged in before.
Thanks
Tim

∴ 219.127.61.37 | 11-Nov-2004 12:24am est | #6335

timtak (http://eigodaigaku.com) wrote:

No, I just checked that, I do seem to be logged in. I just cleared all my cookies from IE. Then logged in, and pressed the view site button. The hello, but not the "we're in" is there.
http://www.eigodaigaku.com/archives/en/000151.html#more
Ah well...it would have been very useful. Perhaps I will just add and edit button that is visible to everyone. Or perhaps I can do somethign to check for my IP.
Tim

∴ timtak | 11-Nov-2004 1:05am est | http://eigodaigaku.com | #6337

Comments closed.

March 2010
SunMonTueWedThuFriSat
 123456
78910111213
14151617181920
21222324252627
28293031 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 2 posts

Recent comments XML

new⇒I hate ASP.NET

I hate ASP... I was doing wonders​with PHP, then suddenly one of my​clients...

Johnies: Mar 17, 6:14am

Quantum physics and free will

I knew you were going to say that....

Tom Massey: Mar 15, 9:26pm

Generated in about 0.099s.

(Used 8 db queries)