php - direct page access prevention -
on site have 2 pages, simple password protected page called login.php
, main webpage called index.php
i trying prevent users directly accessing 'index.php'
- if visitor tried access
index.php
directly, redirectlogin.php
- if visitor entered correct password, allow access
index.php
file.
currently, i'm stuck in loop.
- when try access
index.php
directly, redirectedlogin.php
- ok - when enter password, click enter, i'm sent
index.php
looped `login.php' page
how prevent loop please
// index.php <?php if (!isset($include_allowed)){ die("<meta http-equiv='refresh'content='0;url=\"http://www.myweb.com/login.php'>"); } ?>
-
// login.php <?php $include_allowed = true; ?>
many (sorry if confusing)
please note, there no username, basic password form checks password matches variable before sending 'index.php' page
if ($pass == "mypassword") {
there ton of tutorials on web setting authentication system website. looking using sessions
.
heres article on it: http://www.phpbuilder.com/columns/user-authentication/jason_gilmore05172011.php3
basically, here (having login page), you'd want have like
if( !isset( $_session[ 'islogged' ] ) ) { header( 'location: login.php' ); }
in index.php
more links:
http://www.slideshare.net/chadhutchins/basic-user-authentication-with-php-mysql
http://www.9lessons.info/2009/09/php-login-page-example.html
edit:
you can take at: http authentication php, if want avoid using sessions. can rid of login.php
script
Comments
Post a Comment