/    Sign up×
Community /Pin to ProfileBookmark

Show after login

Hey everyone,
I need a login system, with only two usernames and passwords (I don’t wantall the MySql stuff) :
1 for the admin
1 for the moderator
When the admin logs in, some text/script appears, and when the moderator logs in, it shows some other script.

This is a simple script because it only has two options to log in, I know but I am a newbie at PHP.:.
Can anybody help me?

Thanks
Fire Cat

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@SyCoSep 09.2009 — Add a web form that posts to itself.

In the form have text input and a submit button.

Call the text input 'password' (in this example).

Check the value of the form against your password.

if it matches set a SESSION variable for admin or mod

The SESSION var is now available site wide

Include the function and call to anywhere you want to provide a log out button.

[code=php]<?php
function logout(){
//include this in a sitewide included file anywhere you want to add a logout button
if(isset($_POST['logout']))unset($_SESSION['login']);

if(isset($_SESSION['login']['admin']) || isset($_SESSION['login']['mod'])) {
?>
<form method=post action="<?php echo $_SERVER['SCRIPT_NAME']?>">
<input type="hidden" name="logout" value=1>
<input type="submit" value="logout">
</form>
<?
}
}

//this should be on the same page as the action of the form.
if(!empty($_POST['password'])){
if($_POST['password']=='1m_4dmin')$_SESSION['login']['admin']=1;//admin
if($_POST['password']=='me_m0d')$_SESSION['login']['mod']=1;//mod
if(!isset($_SESSION['login']['admin']) && !isset($_SESSION['login']['mod']))$login_error=1;//wrong password
}

?>
<html>
<body>
<?php
if(isset($login_error))echo 'who hell you?';

logout();//log out button before session vars are used.

?>
<form method=post action="<?php echo $_SERVER['SCRIPT_NAME']?>">
<input type="text" name="password">
<input type="submit">
</form>

<?php
//use admin or mod vars
if(isset($_SESSION['login']['admin']))echo 'admin only text<br />';
if(isset($_SESSION['login']['mod']))echo 'mod only text';
?>[/code]
Copy linkTweet thisAlerts:
@dauphinerSep 19.2009 — Hey!

Great script! I also needed this one, but how can I make it so that when I write the word ADMIN or MOD in a textbox, the script will ask me for a password and if the password is right, it lets me use the word ADMIN in that textbox, and if it is wrong, the value of the txtbox would be "Enter your name" ?
Copy linkTweet thisAlerts:
@MindzaiSep 19.2009 — Just to ad thet SyCo's example will get you started, but you will still have some work to do to make it secure. In particular you will need to protect your session store, and will also want to make sure you are safe against any of the session hijacking / spoofing attacks before deploying this publicly.
×

Success!

Help @Fire_Cat 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 5.28,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...