/    Sign up×
Community /Pin to ProfileBookmark

Killing the current page before a redirect

For a site I’m working on I have a lot of different user access levels for different pages and wrote a function that is called near the top of each page that checks if a user is the correct level and if not, redirects them to a new page with a header redirect…

header(“Location: noaccess.php”);

I had always assumed this would mean the rest of the code on the page was not executed, but the code would still get executed which confused me. And recently I was (correctly?) informed that this is because header is not SUPPOSED to kill the code for the current page, it still executes everything on it.

Basically I’m trying to find some code that will essentially act in the manner of “you don’t belong here, GTFO” and send them elsewhere without even touching the rest of the page. Anyone know how I would do this?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@criterion9Dec 10.2009 — Add exit; after your header redirect. See the header manual
Copy linkTweet thisAlerts:
@xvszeroauthorDec 10.2009 — Oh, that was easy.
×

Success!

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