Jump to content

[SOLVED] Problems with login Script - please help


mazman13

Recommended Posts

I found this script online...it's simple and it will do what i need for now.

But I do have a problem with it.

<?php
    session_start();

    $errorMessage = '';

    if (isset($_POST['txtUserId']))
    {
        $userID = htmlentities($_POST['txtUserId']);
        $userPass = htmlentities($_POST['txtPassword']);

        //replace the following with your MySQL values
        //*********************
        $dbhost = "---";
        $dbuser = "---";
        $dbpass = "";
        $dbname = "fleet_portal";

        //*********************

        $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
        mysql_select_db($dbname);

        // check if the user id and password combination exist in database
        $query = "SELECT * FROM company WHERE `username` = '$userID' AND `password` = '$userPass' AND `enabled`=1";


        $result =mysql_query($query) or die('Query failed. ' . mysql_error());

       if (mysql_num_rows($result) == 1)
       {
          // the user id and password match,
          // set the session
            $_SESSION['test_logged_in'] = true;
            $_SESSION['user']=$userID;

         // after login we move to the main page
		 include"main_login.php";
         exit;
       }
       else $errorMessage = 'Sorry, wrong user id / password';
    }

    if ($errorMessage != '') {
    ?>
            <p align="center"><strong><font color="#990000"><?php echo $errorMessage; ?></font></strong></p>
            <?php
    }
?>

<form id="frmLogin" name="frmLogin" method="post">
    <table width="400" cellspacing="2" cellpadding="2" border="0" align="center">
        <tbody>
            <tr>
                <td width>User Id</td>
                <td><input type="text" id="txtUserId" name="txtUserId" /></td>
            </tr>
            <tr>
                <td width>Password</td>
                <td><input type="password" id="txtPassword" name="txtPassword" /></td>
            </tr>
            <tr>
                <td width> </td>
                <td><input type="submit" value="Login" name="btnLogin" /></td>
            </tr>
        </tbody>
    </table>
</form>

 

As you can see, Ive included the main page they see after they log in...

Well on that page I have a few forms that use PHP_SELF...everytime it goes back to main.php?whatever it pops a login again. What can be done to continue the session?

 


         // after login we move to the main page
		 include"main_login.php";
         exit;
  

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.