Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2014
    Posts
    36

    Why do I need to Login twice??



    Why do I need to enter the login info and click the login button twice before it actually redirects me to the home page where only users that are logged in can see?

    This happens either when I quit and re-open my browser, or when I restart my localhost servers... Basically, when I enter the login info and click login, it just redirects me to back to the login page... And the same goes for the signup script. But if the correct information is entered both times, then it'll log me in. My signup and login scripts go through a redirect page where:

    <?php
    session_start();

    if($_SESSION['username'])
    echo'<script type="text/javascript">window.location="home"</script>';
    else
    echo'<script type="text/javascript">window.location="home"</script>';
    ?>

    I really don't know whats the problem because it always works the second time and however many times I login and out but if the localhost server or web browser was restarted, then it won't.

  2. #2
    It sounds like you are not setting the username correctly in the session before loading the redirect page

    Try doing the following code before the redirect and seeing if this has been added to the session on the first redirect
    PHP Code:
    print_r($_SESSION); 

  3. #3
    Join Date
    Aug 2001
    Posts
    5,597
    Whats the Javascript supposed to do?

  4. #4
    Join Date
    Aug 2014
    Posts
    36
    Quote Originally Posted by zoid View Post
    Whats the Javascript supposed to do?
    That's what I use to redirect... But never mind I got it working by switching to XAMPP instead of MAMP...

  5. #5
    Quote Originally Posted by johndeer65 View Post
    That's what I use to redirect... But never mind I got it working by switching to XAMPP instead of MAMP...
    If your using sole PHP code like in your example then instead of bringing Javascript into the mix you can use PHP to do a redirect, if you search for "PHP header" you should find lots of information about this.

  6. #6
    Join Date
    Aug 2014
    Posts
    36
    Quote Originally Posted by Liam-RackSRV View Post
    If your using sole PHP code like in your example then instead of bringing Javascript into the mix you can use PHP to do a redirect, if you search for "PHP header" you should find lots of information about this.
    Is it the header("Location: url");
    ?

  7. #7
    Quote Originally Posted by johndeer65 View Post
    Is it the header("Location: url");
    ?
    Yes this would be a method to do a redirect in PHP instead of bringing javascript into the mix

  8. #8
    Yeah, setting the redirect location with Location: url is better. Otherwise, browsers that have JavaScript disabled will not be able to use your site

  9. #9
    Join Date
    Aug 2001
    Posts
    5,597
    Quote Originally Posted by dreadiscool View Post
    Otherwise, browsers that have JavaScript disabled will not be able to use your site
    Browsers without Javascript arent able to use the Internet these days

Similar Threads

  1. Plesk: How to login to SSH with customer login?
    By [Axelsson] in forum Hosting Software and Control Panels
    Replies: 8
    Last Post: 02-24-2012, 09:25 PM
  2. PHPBB-3.0.9 Login integration with external login/reg code
    By SunProgrammer in forum Web Design and Content
    Replies: 0
    Last Post: 07-25-2011, 03:31 PM
  3. Replies: 2
    Last Post: 05-19-2011, 07:15 AM
  4. Replies: 5
    Last Post: 01-25-2008, 12:52 PM
  5. Webpage login form intigration with cpanel login
    By mhs in forum Programming Discussion
    Replies: 2
    Last Post: 08-05-2003, 12:13 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •