session - PHP logging in redirection -
i'm working on site , when try login, automatically redirects me login page not allowing me login. think sessions, not sure. if please take me. dashboard based site supposed redirect user there correct dash`board there rank, seems not working. heres login page:
login:
<?php require 'core/config.php'; if(isset($_post['submit'])) { $username = $db->real_escape_string($_post['username']); $password = md5($_post['password']); if(empty($username) or empty($password)) { echo 'you must fill in both boxes!'; } else { $query = $db->query("select * users username = '".$username."'"); while($row = $query->fetch_array()) { $dbpassword = $row['password']; } if($password !== $dbpassword) { echo 'password incorrect.'; } else { $query1 = $db->query("select * users username='".$username."'"); while($rows = $query1->fetch_array()) { $rank = $rows['rank']; } if($rank === 'admin') { $_session['admin'] = '1'; $_session['username'] = $username; echo '<script>window.location="admin/index.php";</script>'; } elseif ($rank === 'partner') { registersession('partner', '1'); registersession('username', $username); header('location: partner/'); } elseif ($rank === 'trainee') { registersession('trainee', '1'); registersession('trainee', '1'); header('location: trainee/'); } else { echo 'you aren\'t member.'; } } } } ?>
code redirect if not logged in:
<?php session_start(); if(isset($_session['partner'])) { $_session['username']; } else { header("location: ../index.php") } ?>
seems session variable partner
not being set. so
instead of
registersession('partner', '1'); registersession('username', $username);
make use of
$_session['partner']=1; $_session['username']=$username;
try add session_start(); ob_start();
on top of config.php
file.
Comments
Post a Comment