header function not working in php after setting session

481

so i have creted this php where if session is set do this and if it isn't set than go to another php so my code goes like this

 <?php
ob_start();
session_start();
if(isset($_SESSION['id']) && !empty($_SESSION['id']))
{
$id=$_SESSION['id'];
    if(isset($id))
    {
        $connection=mysqli_connect('localhost','root','123456789','register');
        $query="select email from register where id='$id'";
        $result=mysqli_query($connection,$query);
        $row=mysqli_fetch_array($result);
        $email=$row['email'];
    }
}

else {header('location: best.php');}
?>

even if i opened this page directly without setting session i am still able to visit and doesn't get redireccted to best.php page how to deall with this problem

People are also looking for solutions to the problem: How to extend PHP with C++?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.