Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Apr 2004
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question registering session variables

    hi!
    im having trouble registering session variables on a particula
    page
    they register every where else
    i can print them on the logincheck.php page and they register in another file that uses the same database

    heres the reduced code

    adminlogin.php

    <table>
    <?
    if (isset($HTTP_SESSION_VARS['valid_user']))
    {
    ?>
    <tr><TD>'Hello Administrator, you are logged in.')
    <a href="login/logout.php">Logout</a>
    </td></tr>
    <?
    }
    else
    {
    if (isset($HTTP_SESSION_VARS['wrongDetails']))
    {
    ?>
    Sorry, there were problems with logging you in.
    </td></tr>
    <?
    unset($HTTP_SESSION_VARS['wrongDetails']);
    }

    ?>
    <FORM name = "Form1" method="post" action="login/logincheck.php">
    <tr><td align = "right" valign = "center">Username:
    &nbsp;<INPUT TYPE="text" NAME="username" maxlength="50" />
    &nbsp;Password:
    &nbsp;<INPUT TYPE="password" NAME="passwd" maxlength="50" size="8" />
    &nbsp;<INPUT TYPE="SUBMIT" NAME="submit" VALUE="Login" />&nbsp;</td></tr>
    </FORM>
    <tr><td>
    <?
    }
    if (isset($HTTP_POST_VARS['username']))
    {
    $username = $HTTP_POST_VARS['username'];
    }
    ?>
    </td></tr>
    </table>



    logincheck.php


    <?php

    session_start();

    $HTTP_SESSION_VARS['direction'] = "../adminlogin.php";
    $go = $HTTP_SESSION_VARS['direction'];
    header("Location: $go");

    if (isset($HTTP_POST_VARS['username']) && isset($HTTP_POST_VARS['passwd']))
    {
    $HTTP_SESSION_VARS['wrongDetails'] = "wrong details";
    $username = $HTTP_POST_VARS['username'];
    $passwdcheck = $HTTP_POST_VARS['passwd'];
    //connect to server and select database
    $conn = mysql_connect("localhost", "root");
    mysql_select_db("alaea",$conn);

    $sql = "select * from loginAccount where username = '$username' AND passwd = '$passwdcheck' ";
    $result = mysql_query($sql,$conn) or die(mysql_error());

    if (mysql_num_rows($result) == 1) {


    $username = mysql_result($result, 0, 'username');
    $accessLevel = mysql_result($result, 0, 'accessLevel');
    $status = mysql_result($result, 0, 'status');

    if ($status == 'enabled')
    {
    $HTTP_SESSION_VARS['valid_user'] ;
    $HTTP_SESSION_VARS['valid_user'] = $username;
    $HTTP_SESSION_VARS['username'] = $username;
    $HTTP_SESSION_VARS['status'] = $status;
    $HTTP_SESSION_VARS['accessLevel'] = $accessLevel;
    }

    }
    }


    mysql_close($conn);

    ?>

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,106
    Thanks
    11
    Thanked 101 Times in 99 Posts
    perhaps its just when you condensed the code but logincheck.php can never parse code after this line ...

    header("Location: $go");
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New Coder
    Join Date
    Apr 2004
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    it was session_start();

    i should have had session_start(); at the very top of adminlogin.php


  •  

    Posting Permissions

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