/    Sign up×
Community /Pin to ProfileBookmark

Non accessable page

Is it possible to have it so a page can not be accessed unless it is called by another page?

I have a page called globalvars.php

I only want users to be able to use it if it is called from index.php, user.php ect.

If they go directly to globalvars.php, I would like them to be redirected to [B]index.php[/B], or if they are logged in [B]user.php?page=home[/B]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@pcthugSep 05.2006 — [code=php]
<?php
// bool logged_in
function logged_in() {
if(isset($_SESSION['session_hex']) && strlen($_SESSION['session_hex']) == 64 && ctype_xdigit($_SESSION['session_hex'])) {
return true;
}
return false;
}

if(strpos($_SERVER['PHP_SELF'], 'globalvars.php') !== false) {
$redirect = 'http://foo.bar/index.php';
if(logged_in()) {
$redirect = 'http://foo.bar/user.php?page=home';
}
header("Location: $redirect");
}
?>[/code]
×

Success!

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