trouble with login script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tolkienarda
    Contributor
    • Dec 2006
    • 316

    trouble with login script

    hi all i have a login script that is simplified with out any extra stuff. and it doesn't seem to work. i think the problem is something to do with session variables. but i am not sure what it is. below are the scripts in their entirety along with a description of all outputs

    first page - login.htm
    Code:
    <html>
    <head>
    <title>login</title>
    </head>
    <body>
    <form action="login.php" method="post">
    Username: <input type="text" name="uname"><br>
    Password: <input type="text" name="pass"><br>
    <input type="submit">
    </form>
    </body>
    </html>
    this is prety self explanitory
    i get a username and password from the user
    then sends it into the login.php script

    [PHP]
    <?
    $uname = $_POST['uname'];
    $pass = $_POST['pass'];
    if ($uname == 'dreimer' && $pass == 'id10t')
    {
    session_start() ;
    $_SESSION['logged'] = 'yes';
    //echo $_SESSION[['logged'];
    header("locatio n: logged.php");
    }
    ?>
    [/PHP]
    now this gets the uname and the pass from post and checks then against the username and password that i have preset. i can get into this if statement fine. i then set a session variable ['logged'] and that is equal to 'yes'. then i redirect the header to logged.php. when i un comment the line that prints the session variable the browser displays 'yes'

    and the final page
    [PHP]
    <?
    session_start() ;
    if ($_SESSION['logged'] != 'yes');
    {
    echo 'ahah';
    //echo $_SESSION['logged'] ;
    //header("locatio n: login.htm");
    }
    ?>
    <head>
    <title>Untitl ed Document</title>
    </head>
    <body>
    logged in sucessfully
    </body>
    </html>
    [/PHP]

    of here i check to see if the session variable isn't yes. and the browse displays 'ahah' and when i un comment the printing of the session variable i get the same output so basicaly i can read session vars off the page where they are set but not off other pages.

    i have worked on this problem for several weeks and tried using cookies to solve the problem as well but nothing seems to work

    if anyone can help me please help

    eric
  • exoskeleton
    New Member
    • Sep 2006
    • 104

    #2
    hi sir... i also tried that one and it wont work...try to place session_start() above all codes...

    [PHP]
    session_start() ;

    $uname = $_POST['uname'];
    $pass = $_POST['pass'];
    if ($uname == 'dreimer' && $pass == 'id10t')
    {

    $_SESSION['logged'] = 'yes';
    //echo $_SESSION[['logged'];
    header("locatio n: logged.php");
    }[/PHP]

    hope this helps...more power

    Comment

    • manirajmurali
      New Member
      • Apr 2007
      • 2

      #3
      <?
      session_start() ;
      if (!isset($_SESSI ON['logged'] = 'yes'))
      {
      echo 'ahah';
      //echo $_SESSION['logged'] ;
      //header("locatio n: login.htm");
      }
      ?>
      <head>
      <title>Untitl ed Document</title>
      </head>
      <body>
      logged in sucessfully
      </body>
      </html>

      Comment

      • tolkienarda
        Contributor
        • Dec 2006
        • 316

        #4
        thanks exoskelton that seemed to fix my problem.


        eric

        Comment

        • tolkienarda
          Contributor
          • Dec 2006
          • 316

          #5
          ok so one more small problem below is where i check to make sure i have logged in successfully

          [PHP]
          <?
          session_start() ;
          $log = $_SESSION['logged'];
          if ($log != 'yes');
          {
          echo $log;
          //header("locatio n: login.htm");
          }
          ?>
          [/PHP]

          the screen shows yes as being the value for $log so am i totaly confused cause i thought != meant not equal to but maybe i am wrong. if anyone sees the problem here please help

          thanks a million

          eric

          Comment

          • exoskeleton
            New Member
            • Sep 2006
            • 104

            #6
            im glad it helped... " != " means not equal to. your right! but you said it still echos yes?

            try this:

            [PHP]if(isset($_sess ion['logged']) {

            echo "You are logged in";

            } else {

            echo "You are not logged in";

            }[/PHP]

            Comment

            • exoskeleton
              New Member
              • Sep 2006
              • 104

              #7
              Originally posted by exoskeleton
              im glad it helped... " != " means not equal to. your right! but you said it still echos yes?

              try this:

              [PHP]if(isset($_sess ion['logged']) {

              echo "You are logged in";

              } else {

              echo "You are not logged in";

              }[/PHP]
              sorry....lack of ")" hehe

              heres the right one:

              [PHP]if(isset($_sess ion['logged'])) {

              echo "You are logged in";

              } else {

              echo "You are not logged in";

              }[/PHP]

              i think your code have just a little problem, it is just the ";" in your if statement.

              [PHP]if(xxxxxxxxxxxx xxxx) ; <------ over here
              {

              echo "xxxxxxxxxxxxx" ;

              } [/PHP]

              Comment

              • tolkienarda
                Contributor
                • Dec 2006
                • 316

                #8
                oh dear it appears that my stupidty is boundless i have been programing for three years in various languages you would think i would have learned where ';' go.

                thanks and sorry it took so long for me to respond my hard disk crashed. ahah

                eric

                Comment

                • exoskeleton
                  New Member
                  • Sep 2006
                  • 104

                  #9
                  Originally posted by tolkienarda
                  oh dear it appears that my stupidty is boundless i have been programing for three years in various languages you would think i would have learned where ';' go.

                  thanks and sorry it took so long for me to respond my hard disk crashed. ahah

                  eric
                  hehe chill sir.. no problem ... :D

                  Comment

                  Working...