/    Sign up×
Community /Pin to ProfileBookmark

Admin Panel Cookies – How would I do it?

Hi,

I am creating an admin panel for my website. I have heard that it is possible to protect it in the following way:

Admins (who should be able to access the admin panel) get a certain cookie.
This cookie then allows them to get into the admin panel when they go to the panel directory.

When anyone else goes to the panel directory, just gets taken back to the homepage, and doesn’t see anything on the panel

How would I do this?

Thanks

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 09.2012 — Typically this is done via PHP session-handling (e.g. starting with the session_start() function, and when the user logs in, add a setting in $_SESSION to indicate whether they are an admin user. Then on your admin-only pages, your logic would be something like:

[code=php]
<?php // this must be the first line: no output of any kind before it
session start();
if(empty($_SESSION['is_admin'])) {
header("Location: http://www.example.com/default_landing_page.php");
exit;
}
// rest of page...
?>
[/code]
×

Success!

Help @leates 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.19,
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,
)...