PHP - session not causing a redirect with header

I am trying to make the user get redirected to the index.html page in case the $_SESSION['loggedin'] is already set. For some reason, it doesn't redirect the user, although the $_SESSION['loggedin'] when echoed returns a value.

if(!empty($_SESSION['loggedin'])) { header('Location: index.html');};

What am I doing wrong here?


header('Location: index.html'); sets an http header which needs to be set before any content is sent, i.e. before any echo. Also you should terminate your script after you set the location header.

Need Your Help

Access denied for a semaphore in a normal application, when it was first created by a service

c++ ms-access semaphore

I create a global semaphore in a library that is used by a normal application and a service.

Mac installer signed with install4j is unsigned

osx code-signing install4j

Using install4j v5.1.14 on Windows 7, I sign our Mac OS X installer with our Comodo certificate. The build output reports that the installer is signed and there are no errors. However, when I downl...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.