session problem - login screen continually reloads after pressing the login button

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default session problem - login screen continually reloads after pressing the login button

    I am trying to get sessions to work on a log in screen to give certain
    users access to certain pages/directories. The problem is that when
    the login button is pushed (or the enter key pressed) the login screen
    redraws, never loading the next page. I don't get any error messages.
    I am using FreeBSD-5.1/Apache-2.0.46/MySQL-4.1.0.1/PHP-4.4.3.4

    Thanks,
    Chip

    I have pasted the code below -

    This is at the top of the page login.php -
    -------------
    <?
    session_start();
    session_register("userid","password");
    if ($submit)
    {
    $db=mysql_connect("localhost","user","") or die ("Error in this query
    >>$sql<< : " .mysql_error());
    mysql_select_db("simradusa",$db) or die ("Error in this query >>$sql<<
    : " .mysql_error());
    $result=mysql_query("select * from user where userid = '$userid'",$db)
    or die ("Error in this query >>$sql<< : " .mysql_error());
    while ($row=mysql_fetch_array($result))
    {
    if ($row["userpassword"]==$password)
    {

    header('Location:
    [url]http://xxx.xxx.xxx.xx/auth_dealers/dealers_page.php');[/url]
    }
    }
    }
    ?>
    ------------

    This is at the top of all pages, before any html tags -
    -------------
    <?
    session_start();
    if(!isset($userid)) {
    header('Location: [url]http://xxx.xxx.xxx.xx/auth_dealers/login2.php');[/url]
    exit;
    }
    ?>
    Chip Guest

  2. Similar Questions and Discussions

    1. Strange problem with Forms authentication: After successfull login, login page is still displayed
      Hi there I have a quite strange problem with my ASP.NET-Application. The application has being deployed one year ago and worked fine till last...
    2. Login/Applicationtoken/Session Variable Problem
      I am having a problem with Logging in and Session variables. I am new to ColdFusion, but program in other languages including PHP and Java. Recently...
    3. Problem with Login Feature By Login Wizard...Please Help
      Hello everyone. I am a beginner and am currently learning Coldfusion MX 7. I ran the login wizard with simple authentication on a folder I want to...
    4. Login to admin system through login screen only
      Hi there, I have an issue relating to login to my asp.net application. Basically i have built the standard login page which compares against the...
    5. The login Screen
      Press CTRL -> ALT -> DEL at the welcome screen -- good luck! Please Send Reply only in newsgroup Tim
  3. #2

    Default Re: session problem - login screen continually reloads after pressing the login button

    Chip <carvin5string@yahoo.com> schrieb:
    > I am trying to get sessions to work on a log in screen to give certain
    > users access to certain pages/directories. The problem is that when
    > the login button is pushed (or the enter key pressed) the login screen
    > redraws, never loading the next page. I don't get any error messages.
    > I am using FreeBSD-5.1/Apache-2.0.46/MySQL-4.1.0.1/PHP-4.4.3.4
    And you're using code from the times of PHP 4.0.x.
    > <?
    Don't use short tags. The are not portable. Use <?php.
    > session_start();
    Seems OK. :-)
    > session_register("userid","password");
    That's not good. In fact it is bad style. Read the documentation at
    [url]http://www.php.net/manual/en/function.session-register.php[/url].
    > if ($submit)
    You rely on register_globals=on. Since PHP 4.2.0, the default value for
    register_globals is off.
    > This is at the top of all pages, before any html tags -
    > -------------
    > <?
    > session_start();
    > if(!isset($userid)) {
    > header('Location: [url]http://xxx.xxx.xxx.xx/auth_dealers/login2.php');[/url]
    > exit;
    > }
    > ?>
    Ouch. What is $userid? You might believe that it contains a variable
    from your session. If register_globals is off, then it doesn't and PHP
    will always send you back to login2.php. You'll find the value in
    $_SESSION['userid'] instead. If register_globals is on, then it _might_
    contain the id from the session. On the other hand it could be a clever
    intruder who just calls your page with page.php?userid=42. So, don't
    work with activated register_globals.

    This leaves you with some work to do. Check the setting of
    register_globals in the php.ini. If it's on, then switch it off. With
    activated register_globals you have to work hard to make your code
    secure. With deactivated register_globals you have to work to make it
    insecure.

    To find errors from uninitialized variables set the error_reporting to
    E_ALL, so that you get all notices and warnings during the development
    of your code.

    Write data to a session with:
    $_SESSION['example'] = $value;

    Access data in a session with:
    echo ($_SESSION['example']);

    Access data from a form with:
    $_POST['username']
    or
    $_GET['username']
    according to your posting method.

    Check [url]http://www.php.net/manual/en/language.variables.predefined.php[/url] for
    details about these "superglobals".

    Regards,
    Matthias
    Matthias Esken Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139