0

I am unable to redirect my login page to admin panel

This is authentication.php file which will redirect the form to authentication file

<?php session_start();
include("assets/php/conn.php");
$uname = $_POST['email'];
$pswd = $_POST['password'];
$e= "";
$p = "";
$check = true;
$rows = 0 ;

if(!empty($uname) and !empty($pswd))
{
$result = mysqli_query($conn, "select * from login");

while($rows = mysqli_fetch_array($result))
{
$e =  $rows['email'];
$p =  $rows['password'];

if($e == $uname and $p == $pswd)
{
$check = false;
$_SESSION['email'] = mysqli_fetch_array($result);

header("location:adminpanel/panelindex.php");  // The problem is here
exit();
}

$rows++;
}

if($check)          
{
header("location:login.php?a=error");
exit();
}

}
else
{
header("location:login.php?a=fill the fields properly");
}

?>

This is admin panel file "panelindex.php"

<?php session_start();
include("assets/php/conn.php");
$success = "";
$msg = "";
$msg2 = "";
$info = "";
echo $_SESSION['email'];
if(!isset($_SESSION['email']))
{
    header("location:../login.php");
}
if(isset($_GET['info']))
{
    $info = $_GET['info'];
}

if(isset($_GET['info']))
{
    $success = $_GET['info'];
}
if(isset($_GET['msg']))
{
    $msg = $_GET['msg'];
}
if(isset($_GET['msg2']))
{
    $msg2 = $_GET['msg2'];
} 
?>      
<?php echo $msg; ?>
<?php echo $msg2; ?>
<?php echo $info; ?>
</table>
<fieldset style="width:80%; margin:auto;">
<legend>
        User's Data
</legend>
<table class="hoverTable">

<tr>

<th>
Email
</th>

<th>
  Password
</th>
<th>
Action
</th>
</tr>
<?php
$result = mysqli_query($conn, "select * from login");
while($rows = mysqli_fetch_array($result))
{
?>     

<tr>
<td>
<?php echo $rows['email']; ?>
</td>
<td>
<?php echo $rows['password']; ?>
</td>
<td>    
<a href="edit.php?id= <?php echo $rows['id']; ?> "> Edit</a> ,<a href="assets/php/del.php?id=<?php echo $rows['id']; ?>">Del</a>
</td>
</tr>
<?php
$rows++;
}
?>
</table>
<?php echo $success; ?>
</fieldset>
<a href="../imageupload.php">Add SLider Image</a>
</body>

</html>

Actually my whole code is working fine just there is an issue in header i can not redirect my login page to admin panel`s page but if I choose another location in header it is working fine the issue is only with admin panel page

AZEEM ZAIDI
  • 3
  • 1
  • 4
  • `adminpanel/panelindex.php` looks a little weird. Does it work if you replace that with an absolute URI? If the other redirects work, and only this one doesn't, then how does it differ? – ficuscr Aug 06 '19 at 22:07
  • Did you note that `header("location:adminpanel/panelindex.php"); ` there is no space between location and the url. Please change it as `header("Location: adminpanel/panelindex.php"); ` and let us know what happens – Nipun Tharuksha Aug 07 '19 at 01:47
  • Nothing happened – AZEEM ZAIDI Aug 07 '19 at 06:40

2 Answers2

0

please just try to use ob_start(); before header() it will help;

An example

ob_start();
header("Location:adminpanel/panelindex.php");
exit();
0

Try This Code

header("location:adminpanel/panelindex.php");

or

header("Location:adminpanel/panelindex.php");