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();
}
?>

Recommended Answers

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

should be :

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

All 3 Replies

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 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.