I am a newbie to php, i occasionally find a problem, I open the page "index.php" on a chrome browser, then I left for lunch, then I come back and click the link in page "index.php", it did head to "login.php", but laterly I find a record in my database. the username is null, in another words, the green colored code in main.php is executed somehow. I guess it's because the session have been expired when i came back, but why the session check did not work properly?
the code like this
the index.php
<?php
session_start();
if($_SESSION['username']=='')header("Location: login.php");
echo "<a href='main.php'>home</a>"
?>
the main.php
<?php
session_start();
if($_SESSION['username']=='')header("Location: login.php");
$username=$_SESSION['username'];
$sql="insert into table1 values($username,"something else");
$db->query($sql);
....
?>