i have a index.php i just want only logged in user can access the page my code . in the index page is

<?php
error_reporting(0);
$authorized=false;
@session_start();
if(isset($_SESSION['$myusername']) && isset($_SESSION['$mypassword']))
{
    $authorized = true;
}

if(!authorized)
{
    header('location:login.php');
    exit();
}
?>
if(!authorized)
{
    header('location:login.php');
    exit();
}
?>

should be :

if($authorized == false)
{
    header('location:login.php');
    exit();
}
?>

if(!authorized) - wrong

if(!$authorized) - correct

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.