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'

  1. if visitor tried access index.php directly, redirect login.php
  2. if visitor entered correct password, allow access index.php file.

currently, i'm stuck in loop.

  1. when try access index.php directly, redirected login.php - ok
  2. 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.techrepublic.com/forum/questions/101-274721/good-tutorial-for-authenticated-web-sessions-using-phpmysql

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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -