PHP error- Cannot modify header information
Hi!
I'm just learning PHP, I made this code that will redirect automatically to index.php every time the session variable is not set or it is being destroyed by logout. I am using header function for this. It worked perfectly on my laptop, but when I had uploaded it on a free web hosting site, every time I run the code, it will display an error on the very top of the page saying: "Warning: Cannot modify header information – headers already sent by (output started at /home/database/admin.php:2) in /home/database/home.php on line 2 "
I just don't get what it really means, I've been trying to transfer anywhere my code but still, it displays the error above.
What are the possible solutions for this?
Is this related to my php.ini configurations?
I appreciate all your help..
This is the code:
<?php
if (!isset($_SESSION['username']) AND !isset($_SESSION['password'])) {
header("Location: index.php");
exit();
}
?>
Thank you
James Field








