Access denied error after login When i log in to drupal doesn't matter with any account either admin or normal user. I get error Access Denied. I then again try to login and it works fine. What is that problem?
My theme was shipped with its own drupal so i guess they might have done some thing wrong.

I feel some session issue because my error messages on drupal valiation forms also occurs one page delayed. So if a submit a invalid form the page post back and hight light the fields with red color but don't show any message. When i go to any other page the error message dive comes up. This happens on both front end and admin panel forms.

Update: I forgot to mention that i am using a custom template for user login page.

Here is the code for my user login template. I am not sure if this is causing issue or something else.

&lt;?php
     // we aren't getting messages, get them manually
            if (isset($_SESSION['messages'])) {
                echo '&lt;div class="messages"&gt;';
                foreach($_SESSION['messages'] as $type=&gt;$messages) {
                    echo "&lt;p class=\"$type\"&gt;".implode("&lt;/p&gt;&lt;p class=\"$type\"&gt;", $messages)."&lt;/p&gt;";
                }
                echo '&lt;/div&gt;';
                unset($_SESSION['messages']);
            }
?&gt;
&lt;h1&gt;Login&lt;/h1&gt;
&lt;div class="qualia-user-login-form-wrapper"&gt;
  &lt;?php print drupal_render_children($form) ?&gt;
&lt;/div&gt;


Updatd Part: I found the culprit i.e my own module

Actually i got the problem. But coudln't find the work around. I have a custom module that redirects user to paypal when he is creating account on my site. I put the $form and $form_state values in session and when the user return back from paypal i pass both variables to user_register_submit function to resume the process of creating account. For this purpose i have to put @session_start() at the start of my module file. This works fine in case of my paypal process. But because of sesion_start() my login flow is disturbed. What can i do to resolve this issue as i need session to hold form and form state
What worked for me was enabling and configuring the $cookie_domain variable in settings.php (because I have a site that can be accessed by 2 different domains).

Pay attention to the comment before this variable! The domain name must start with a period. EX:

$cookie_domain = '.example.com';

Good luck!