scriptygoddess

26 Apr, 2002

More info on restricted post hack

Posted by: Jennifer In: MT hacks

A few things here. First Below is a sample Main Index Template so you can see how all that junk is set up on the templates. (I hope it doesn't confuse people even more! LOL!)

Also – the author of the blog software b2 had some suggestions for me on how to improve the code on this – which I have not yet implemented. But you can see his comments here.

Ok – now the template…

<?
include("/home/PATH_TO_FILES/header1.php");
?>
<!– I use includes for my header and footer HTML files. Makes it easier for rebuilds –>
<MTEntries>
<p class="date">
<MTDateHeader>
<$MTEntryDate format="%B %d, %Y"$></p>
</MTDateHeader>
<a name="<$MTEntryID pad="1"$>"></a>
<?
$ip = $REMOTE_ADDR;
$cookievalue = $HTTP_COOKIE_VARS["id"];
$array = parse_ini_file("/home/PATH_TO_FILES/accesslist.ini");
$cat = "<$MTEntryCategory$>";
$restricted = "restricted";
$accessallowed = FALSE;
if (in_array($ip, $array, TRUE) || in_array($cookievalue, $array, TRUE))
{
$accessallowed = TRUE;
}
$pretitle = "";
if (!strcasecmp($cat, $restricted)) {
$pretitle = "Restricted Post: ";
}
?>
<p class="headline"><? echo $pretitle; ?><$MTEntryTitle$></p>
<!– the "pretitle stuff is so that if it's a restricted post, it'll automatically put the text "Restricted Post:" before the actual title –>
<?
if ((!strcasecmp($cat, $restricted)) && !($accessallowed))
{
PRINT "<p>This post is a restricted post. To gain access to view this post, simply click <a href='mailto:scriptyATscriptygoddessDOTcom?subject=access_for_";
PRINT $cookievalue;
PRINT "_and_";
PRINT $ip;
PRINT "' >*here*</a> and send me an email (make sure you do NOT change the subject line), and I will give you access ASAP. (Access is usually given within 6 hours, or so (it's done manually)… if after that time you're still not able to see the restricted posts, please email me to let me know and I'll give you password access).</p>";
PRINT "<p class=\"footer\">To gain access via password <a href=\"<$MTEntryLink$>\">click here</a></p>";
} else {
print <<<EOF
<$MTEntryBody$>
</p>
<MTEntryIfExtended>
<p><a href="<$MTEntryLink$>">yadda yadda yadda… (click here to read more)</a></p>
</MTEntryIfExtended>
<p align="right" class="footer">posted at <$MTEntryDate format="%I:%M %p"$>
<!– below is the script for showing custom text based on if there are comments or not –>
<script language=javascript>
document.write(' || <a href="<$MTEntryLink$>">permalink</a>');
</script>
<MTEntryIfAllowComments><script language=javascript>
<!–
document.write(' || <a href="<$MTEntryLink$>#comments">')
if (<$MTEntryCommentCount$> == 0)
{
document.write('speak up</a>')
} else if (<$MTEntryCommentCount$> == 1)
{
document.write('<$MTEntryCommentCount$> voice</a>')
} else if (<$MTEntryCommentCount$> > 1)
{
document.write('<$MTEntryCommentCount$> voices</a>')
}
//–>
</script></p>
</MTEntryIfAllowComments>
EOF;
}
?>
</MTEntries>
<?
include("/home/PATH_TO_FILES/footer1.php");
?>

24 Responses to "More info on restricted post hack"

1 | zalary

April 27th, 2002 at 6:21 pm

Avatar

i'm having a little problem getting this set up, and was hoping you might be able to offer some insight.

i got the code and everything set up, and it seems to be okay, but only as long as the allowaccess.ini is blank.

if i try to add my own (or anyone else's) IP or computer id, my entire page displays a 500 Server Error. i've tried putting inside and outside the public_html and also tried re-chmoding it to 777, but nothing seems to work.

any ideas? thanks!

2 | Jennifer

April 27th, 2002 at 9:40 pm

Avatar

I replied by email Zal… :)

3 | Jennifer

April 27th, 2002 at 10:05 pm

Avatar

Just a note for anyone else who is trying this script and having problems – it seems some servers need that accesslist.ini file set up like this:

001 = "123.45.678"; //this is line one
002 = "98.765.432"; //you can add comments here
003 = "1231412314"; //theres a cookie… etc.

That seemed to fix Zal's problems. It may have something to do with the way the server is set up… not sure

4 | Lynda

April 28th, 2002 at 10:59 pm

Avatar

I always had a problem with the b2 guy. He used to troll the Greymatter forums with posts about why PHP was so much better than CGI.

Several of the things he mentioned as "bad coding practices" were theory (ie – his opinion). And I fail to see how some of the suggestions we made (ex, the suggestion to put the file outside of your public_html, which is always more secure than leaving it inside) were "bad coding practices"

I've had enough of that guy though. There are much better places to learn "good coding practices" than from him.

No, no, I'm not bitter. :) hehe.

5 | zalary

April 29th, 2002 at 9:18 pm

Avatar

as a side note, i was playing with Jenn's code in an attempt to be able to write a brief description of each category at the top of said category archive page. if anyone is interested, this is what i came up with… (may be bulky code, may be a better way to do this)

first, i made an mt module called cattitle and inside it i put this (for brevity's sake, this is the code for 2 categories, you can add as many categories as you want.

<?
$cat = "";
$blogger = "blogger";
$daily_ramblings = "daily ramblings";

$pretitle = "";
$precomment = "";

if (!strcasecmp($cat, $blogger)) {
$pretitle = "Blogger Entries";
$precomment = "the following entries were imported to Moveable Type from Blogger, and predate the availability of comments. You can, however, add comments now, for what it's worth";
}

if (!strcasecmp($cat, $daily_ramblings)) {
$pretitle = "Daily Ramblings";
$precomment = "lots and lots of entries full of pure drivel live here. lots of time i just use my blog as a place to recap my days, in a dear diary kind of way. if this sort of thing doesn't interest you, try checking out a different category.";
}

?>

<? echo $pretitle; ?>
<? echo $precomment; ?>

so, save that module, and then go into Category Archive Template, and right above you want call that module

save, publish, and let me know if you have any problems.

thanks to Jenn for letting me play with her code and suggesting i post this here :)

6 | Lynda

April 29th, 2002 at 9:25 pm

Avatar

That's a cool snippet, zalary! I've been meaning to put together something similar for my journal, but I haven't had the time or need to do it yet. Still working on getting everything categorized. hehe. :)

7 | randy

May 3rd, 2002 at 12:31 pm

Avatar

Kind of a related question.

I use moveable type for a family happenings kind of blog and would like to restrict access to the entire site. I only want to give access to family & close friends. I think I have figured out how to do that using .htaccess & .htpassword but I want to get rid of that unattractive and annoying security popup and bring the functionality into my .htm page.

Any ideas or am I trying to do the impossible.

Thanks for a great site it is much appreciated!

8 | Jennifer

May 3rd, 2002 at 12:49 pm

Avatar

I actually have another blog about my daughter and password protect it with a php script… However, i've been having some trouble with that particular script (I can't find the link to the script author at the moment). It's supposed to set a cookie on your machine so you only have to login once.. but it's not remembering people…

In any case – this is something that I plan on working on over the weekend (hopefully) I'll keep you posted.

9 | Jennifer

May 3rd, 2002 at 1:38 pm

Avatar

Doing a quick search on google I found this. Althought I can't remember if that's the one I used – either way I was having some trouble with it… and will report back with an update. :)

10 | Alex

July 4th, 2002 at 10:46 pm

Avatar

I am having problems with the access list, and I guess, I just am not understanding the format it's supposed to be in? I originally did it as

ip cookie

that didn't work so I tried

cookie ip

that still didn't work, so then I tried lines with just the ip or the cookie on them. Can you give me an example 3 or 4 lines from your access ini file?

11 | alex

July 4th, 2002 at 11:12 pm

Avatar

nevermind. I'm a dork 😛

12 | Mariann

October 15th, 2002 at 2:05 pm

Avatar

Do you have an example of the template when you use both password protected and IP verification techniques? The first Scripty Goddess post on restricted entries mentions using a password, but I can't figure out where I should put that part of the script in this template sample. Help!

13 | Jennifer

October 15th, 2002 at 2:53 pm

Avatar

The way these samples are set up is that you have to go to the individual entries page to view the restricted post via password (see the template on the original post here)
The template shown in THIS post shows the MAIN INDEX page (where as the other shows indiviual entries page with the password access)

Are you asking for a template for the MAIN INDEX page that allows for password access?

14 | C.

December 22nd, 2002 at 11:50 am

Avatar

I'm having some trouble getting the script up and running. I've double and triple checked the script against this one, and I don't see anything different between what I'm putting onto my site from what's here, but I'm having a weird sort of problem…

Instead of showing up only on "restricted" posts, I'm getting pieces of code spit out into every entry; it looks something like this:

damn job. To gain access via password click here
"; } else { print <<entry text here
11:22 AM | comments – 0 | Trackback – 0
EOF; } ?>

When I tried making a test post in the restricted category, I got the same thing. It won't display the "send email for access" message.

Could anybody think of something that would be causing this?

(I removed the code from my site for now, since it looks silly to have bits of code sticking out. If anyone would like to take a look at it, let me know.)

Thanks! :)

15 | Cathy

March 6th, 2003 at 3:43 pm

Avatar

I added this code to my main index page, and now all of a sudden the left sidebar with the calendar, links, etc is showing up at the bottom of my page. Any ideas on why this would happen?

16 | Jean

August 10th, 2003 at 10:41 pm

Avatar

I'm having a similar problem to Cathy's. When I add the code, my right sidebar moves to the bottom-left corner of the page.

Also, when I click on the link to enter a password, I get taken straight to the entry without having to input any password. Please help.

17 | Jean

August 10th, 2003 at 10:53 pm

Avatar

Okay, I figured out why the CSS was wonky, but I'm still unsure about the password input…

18 | Jennifer

August 10th, 2003 at 10:59 pm

Avatar

Did you install the script on your individual archives template?

19 | Maggie

February 25th, 2004 at 10:51 am

Avatar

As far as the "FORM EMAIL INSTRUCTIONS:" go, does anyone have the code for "(you can make this a popup later on using normal javascript popup commands)"? Also, in the CLICK HERE TO REQUEST ACCESS. part of the code, where it says href=\"#\", how would that look after it is filled in? Something like href=\"http://www.yoursite.com/pathto/form.php\"? Sorry for repeating part of this. I was thinking the reason no one has replied to my previous comment was because I had been unclear. I would really appreciate your help with this. Also, is there a way to keep the comments private as well. In a test entry for the restricted entry, if you were to go here, you can see the comments related to the restricted entry.

20 | Crys

April 18th, 2004 at 3:09 pm

Avatar

Does anyone know of a way to prevent restricted entries from being viewed in archives and the search function, using this hack?

21 | Jennifer

April 18th, 2004 at 3:44 pm

Avatar

Just posted this same response on another related post, but I'll copy/paste:
The script needs to be put on every archive template that displays your post. So that means your main index template, individual archive, monthly and or category archives. Anything that displays the body and/or extended entry of your posts.

22 | Ria

April 30th, 2004 at 6:38 pm

Avatar

Thanks for the wonderful script Jennifer. XD I was able to get it working but I do have one issue. When visitors request access via e-mail, the subject header is missing the cookie id.

Example: mailto:princesa_riaAThotmail.com?subject=access_for__and_01.2.3.04.05

But when they refresh the site, the cookie ID becomes visible. Also, when I use the pop-up form to test it I receive the following in the body of the e-mail:

Name: Ria
E-Mail: princesa_riaAThotmail.com
IP and COOKIE ID:

Any help will be appreciated. Thanks!

23 | Jennifer

May 2nd, 2004 at 4:00 pm

Avatar

Ria – this part from the original code:

<?
if (!isset($id)) {
srand((double)microtime()*1000000);
$randval = rand();
setcookie("id",$randval,time()+126144000,"/",".YOURSITE.COM",0);
}
?>

Change it to this and it should work fine:

<?
if (!isset($id)) {
srand((double)microtime()*1000000);
$randval = rand();
setcookie("id",$randval,time()+126144000,"/",".YOURSITE.COM",0);
$HTTP_COOKIE_VARS["id"] = $randval;
}
?>

24 | Ria

May 4th, 2004 at 1:11 am

Avatar

Thank you, Jennifer!!!! It worked. You are awesome. I will forever worship you! XD

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements