PHP: session controll the pages from unauthorized access, with level -
aim
a simple login page check user credentials if correct in database lets user login , check on other pages if sessoin provide let user operation in pages else redirect them out login page authentication.
the connection set , working fine:
the session has started:
for checking input , echo variables simple checking function:
function check_param($val){ $value1=addslashes($val); $string1=htmlspecialchars($value1); $string2=strip_tags($string1); return $string2; }
now user authenticate trough form , runs function check if can login pages , pass $_session['username'] , $_session['password'] , $_session['level'] next page , store browser tell getting destroy command.
public function auth($name = '', $password = '', $level=''){ $sql = "select count(*) dab_users `name`=:name , `password`=:password , `level`=:level "; $result = $this->conn->prepare($sql); $passme = hash_value(check_param($this->password)); $result->execute(array( ":name" => check_param($_post['name']), ":password" => check_param($_post['passwrod'), ":level" => check_param($_post['level']) )); $num = $result->fetchcolumn(); if($num==1){ $_session['level'] = $_post['level']; $_session['is_log'] = 1; header("location:home/index.php"); }else { $result->execute(array( ":name" => check_param(''), ":password" => check_param(''), ":level" => check_param(''))); echo "wrong password , user"; } }
this works ok , can access pages after giving correct password on view of index page after authentication user can access here way have manage restrict unknown user or blank session or correct session page.
index.php:
<?php if(!empty($_session['is_log'] && !$_session['level'] == 101){ header("location:../login.php"); } else { ?> <h1>header + content + footer</h1> <?php } ?>
question: here after submit form correct user name , password , level in database login index page, , on echoing session see level , is_log on aut class been set. , (if) on index page works , redirect user if not login...
- is secure?
- is enough session restriction?
- is fine session control ?
- am doing right session controlling?
- any suggestion or tutorial?
your authentication systems works, if fail check control security on each page have? should learn front controller pattern , see if suits needs better.
related front controller pattern, advice read 2 chapters fantastic symfony documentation (they related symfony talk http / php in general , how , why framework may benefit code in end):
and if worried security seem (and of course should), take @ owasap top 10 web vulnerabilities (a must read every web developer).
specific question session hijacking problem, can find more here.
Comments
Post a Comment