redirect a user to the homepage when he access a page without logging in
<p>Well I have a question, See for example I have some web pages on my website like <code>profile.php</code> , <code>photos.php</code> and some more</p>

<p>Okay when user logs in he will be redirected to his <code>profile.php</code> but i got a question suppose if user enters this url without logging in like www.somewebsite.com/profile.php and hits enter. The browser will direct him to the profile.php page and the profile.php throws out errors like undefined variables and all because we load the profile.php page according to user input on the homepage</p>

<p>So I want to redirect user to homepage whenever he opens any webpage on mywebsite and send him a message that please login to continue.</p>

<p>So then I thought and I got a solution. I thought to use <code>session_start()</code> and give some session value on the index page  and in all other pages i would check <code>isset()</code> so if session is set profile.php page executes else it will redirect him to homepage </p>

<p>Something like this</p>

<p>all otherwebpages will have this on the top</p>

<pre><code>    &lt;?php
    session_start();
   if(!(isset($_SESSION['unique'])))
    {
    header("Location: www.someexample.com");
            exit;

    }
</code></pre>

<p>but let me know is this the way to do? or is it a bad way of doing it? are there any better solutions in doing so. any help is greatly appreciated.Thanks</p>
