Results 1 to 5 of 5

Thread: [RESOLVED] PDO Session Handiling

Threaded View

  1. #1
    Join Date
    Jun 2009
    Chi town. IL68 ICAO code home airport, literally.

    resolved [RESOLVED] PDO Session Handiling

    Good evening all!

    Hope is all well and that someone can help me out here. I am writing a login script for a website of mine here, and I am new to the whole PDO thing along with sessions. This being said, I have successfully tested this code, and it is not throwing any errors, and executes the way I want to. Thing is, I don't know how to carry over the session from page to page. I have
    at each page but I know I am doing something wrong, and I am nearly 99.99% sure I am setting the session incorrectly or not at all.

    Here is the login script:
    PHP Code:
    //pull variables
    $User $_POST['user_name'];
    $Pass $_POST['password'];
    $ENC sha1($Pass);
    $ERRmsg "";

    //Checks to see if login button was pressed
    //Checks to see if user actually put in data
    if(empty($User)) $ERRmsg .= '<p>You did not enter a user name, please go back and enter your user-name. </p>';
    $Pass)) $ERRmsg .= '<p>You did not enter a password, please go back and enter your password. </p>';
    //Checks to see if error message is empty, if true, then proceeds with rest of code
    //Uses the input from the from to match the username and password and checks it against the 'Users' table
                        //Opens the connection to MySQL
    try {
    $LGC = new PDO('mysql:host=localhost; dbname=******''**********''*********');
    //Prepares the SQL Statement
    $SLU $LGC->prepare(
                                    Username = :Uname
                                    Password = :DbPass
    //Binds the variables for security
    //Executes the SQL Statement matching the information given
    //Sets the results into an array
    $result $SLU->fetch(PDO::FETCH_ASSOC);
    $Uname $result['Username'];
    $Active $result['Active'];
    $UID $result['UID'];
                                catch (
    PDOException $ex) {
    $msg $ex->errorInfo;
    "<h1 style='color:red'>Error LG_01, Please contact the administrator!</h1>");
    //Checks if account is a valid account
    if($Active == 0$ERRmsg .="You Need to confirm you account first before you log-in";
    $Active == 3$ERRmsg .="Your account has been disabled for security reasons, contact the administrator for more information";
    //Checks to see if error message is empty
    $_SESSION['Username'] = true;
    $_SESSION['Password'] = true;
    'Successfully logged-in';
    //Shows you error message
    "<div id=posts>"$ERRmsg."</div>");
    "You cant do that!");
    and here is the page where the first session should come into play if you are logged in, but the session doesn't carry over to the page. Can anyone help me out?
    PHP Code:

    //if the user is logged in show the downloads page
    if( isset($_SESSION['true']) )  {?>
    <p>Thank you for logging in</p>
    <div id="bg-cyan">
        <div id="body body-s">
            <form method="post" action="loginscript.php" id="register-form" class="sky-form">
            <h1>Please Login</h1>
                        <label class="input">
                            <i class="icon-append fa fa-user"></i>
                            <input type="text" name="user_name" id="user_name" placeholder="User Name">
                            <b class="tooltip tooltip-bottom-right">Please enter your User Name"</b>
                        <label class="input">
                            <i class="icon-append fa fa-lock"></i>
                            <input type="password" name="password" id="password" placeholder="Password">
                            <b class="tooltip tooltip-bottom-right">Please enter your password</b>
                <button type="submit" class="button" name="Login">Submit</button>
                <p>If you are not registered, please <a href="http://www.wartachicago.org/test/ssignup.php">register</a> here.</p>
    <? ?>
    Last edited by NogDog; 08-18-2014 at 10:33 PM. Reason: changed CODE tags to PHP tags
    For want of a nail...the horseshoe was lost. For want of a horseshoe, the steed was lost. For want of a steed...the message was not delivered. For want of an undelivered message.....the war was lost.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Recent Articles