/    Sign up×
Community /Pin to ProfileBookmark

forcing a user to enter a password…

ok…I have a NEW forum…other than my OTHEr NEW FORUM…i hve 2 now…

How do I write a cookie saying a user entered the correct password, and then allow them to enter my forum?

I don’t want people who don’t know the password to be able to see whats in there…so how do I then check the cookie?

I posted this in php, because my forum is php…

to post a comment
PHP

17 Comments(s)

Copy linkTweet thisAlerts:
@neenach2002authorAug 02.2003 — oh

so insert

<? include_once("protect.php"); ?>

into the the top of the protected pages?

k, i'll try it
Copy linkTweet thisAlerts:
@neenach2002authorAug 02.2003 — it won't work...

It gives me the following error three times:

Warning: Cannot add header information - headers already sent by (output started at http://cgi-bin.spaceports.com/~psswd/protect.php:1) in /home3/psswd/public_html/phpBB2/includes/page_header.php on line 474

Warning: Cannot add header information - headers already sent by (output started at http://cgi-bin.spaceports.com/~psswd/protect.php:1) in /home3/psswd/public_html/phpBB2/includes/page_header.php on line 476

Warning: Cannot add header information - headers already sent by (output started at http://cgi-bin.spaceports.com/~psswd/protect.php:1) in /home3/psswd/public_html/phpBB2/includes/page_header.php on line 477

and THEN it displays what I want hidden...
Copy linkTweet thisAlerts:
@Da_WarriahAug 02.2003 — you need to make sure that the cookie is set before ANY output by the code...that includes print, echo, return, etc, which displays anything to the page...
Copy linkTweet thisAlerts:
@neenach2002authorAug 02.2003 — but I'm NOT using a cookie, I'm STILL using that code that pyro posted...THAT doesn't work...I haven't even been able to try a cookie, because the code hasn't been posted yet...
Copy linkTweet thisAlerts:
@Bootsman123Aug 02.2003 — Post your full code here between [code=php] tags.
Copy linkTweet thisAlerts:
@neenach2002authorAug 02.2003 — ok...for which?
Copy linkTweet thisAlerts:
@Bootsman123Aug 02.2003 — The page in which you want to set a cookie or session if doing it with php.
Copy linkTweet thisAlerts:
@neenach2002authorAug 02.2003 — too long...It's an attachment instead...

dunno which one it is that should make the cookie...

? ? ?

[upl-file uuid=3ac49d42-92be-4d70-b604-7c818026fc97 size=467B]passwordreader.txt[/upl-file]
Copy linkTweet thisAlerts:
@Bootsman123Aug 03.2003 — [code=php]
<?PHP

# Change the below lines to the results that makepass.php gave you
#
$user = 'f1d05700a113ae40dd1d281e82cf371e';
$pass = '130fbd90204fe13e85a35ca2a6d4e386';
#
# Change the above lines to the results that makepass.php gave you

if(md5($_POST['username']) == $user && md5($_POST['password']) == $pass)
{
setcookie ("verified", true);
header ("Location:http://cgi-bin.spaceports.com/~psswd/phpBB2/");
}
else
{
echo ("Incorrect Password");
}
?>
[/code]


You are setting a cookie. But if that doesn't works, then it could also be that your browser hasn't accepted the cookie or you could try this:

setcookie ("verified", TRUE, time() + 60*60*24*2);

/*
experation after 2 days */
Copy linkTweet thisAlerts:
@neenach2002authorAug 03.2003 — cool...now I need the cookie reader...^_^x
Copy linkTweet thisAlerts:
@Bootsman123Aug 03.2003 — Now I see something really strange:

header ("Location:<a href="http://cgi-bin.spaceports.com/~psswd/phpBB2/" target="_blank">http://cgi-bin.spaceports.com/~psswd/phpBB2/</a>");

I always thought that you couldn't use html in a header, that it had to be something like this:

header ("location: page.html");

And how you read the cookie:

$_COOKIE['verified'] or $verified depending on your settings:
Copy linkTweet thisAlerts:
@neenach2002authorAug 03.2003 — I'm confused....how exactly do I use that code in a page? where does it go?
Copy linkTweet thisAlerts:
@pyroAug 03.2003 — [i]Originally posted by Bootsman123 [/i]

[B]I always thought that you couldn't use html in a header[/B][/QUOTE]
That is correct. The code above is a simple formatting error by the forums. If the Automatically Parse URLs checkbox was not unchecked, it screws up the code...
Copy linkTweet thisAlerts:
@neenach2002authorAug 03.2003 — ???

ok now I'm confused...Now I see something really strange:

header ("Location:<a href="http://cgi-bin.spaceports.com/~psswd/phpBB2/" target="_blank">http://cgi-bin.spaceports.com/~psswd/phpBB2/</a>");
[/QUOTE]

what do you mean?
Copy linkTweet thisAlerts:
@pyroAug 03.2003 — As I explained above, that is due to a formatting error by the forums. It should be:

[code=php]header ("Location:http://cgi-bin.spaceports.com/~psswd/phpBB2/");[/code]
Copy linkTweet thisAlerts:
@neenach2002authorAug 03.2003 — oh...

i STILL need to know where the code goes...?
×

Success!

Help @neenach2002 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...