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 5 of 5

Thread: user LOgin

  1. #1
    New Coder
    Join Date
    Apr 2013
    Posts
    11
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question user LOgin

    Dear Friend's!
    i have a problem in my user login page.
    the problem is that when user login and i click the next page or link, then it will disappear, and when i back to the perivous page then it will not show the user?
    what can i do,,,,
    my login code is ..
    Code:
    <?php 
     include './header.php'; 
    include 'connection.php';
    if(isset($_POST) && count($_POST)>0) {
        $user = $_POST['username'];
        $pass = $_POST['password'];
        
        $sSQL = "SELECT * FROM ulog WHERE User_Name ='$user' AND Password = '$pass'";
        
        $result = mysql_query($sSQL) or die(mysql_error());
        
            if(mysql_affected_rows() > 0) {
            $row = mysql_fetch_object($result);
            
            $_SESSION['username'] = $row->User_Name;
            $_SESSION['password']  = $row->id;
            echo "<h4 id='welcome'>welcome &nbsp<a href='#'> $user</a></h4>";
              
        }
        
        else
        {
            header("location:signup.html");
        }
        }
        
    ?>

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,916
    Thanks
    15
    Thanked 227 Times in 227 Posts
    Answer, put the login in $_SESSION. Learn to use session to hold information during the users visit.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #3
    New Coder
    Join Date
    Aug 2013
    Posts
    10
    Thanks
    0
    Thanked 1 Time in 1 Post
    Hi,

    Don't put this inside the if-statement where you check for POST variables:
    Code:
    echo "<h4 id='welcome'>welcome &nbsp<a href='#'> $user</a></h4>";
    It will only execute the code above if the form is submitted.
    When you go back to the previous page, the form is not being submitted meaning the code won't show.

    Do something more like this:
    Code:
    if(isset($_POST) && count($_POST)>0) {
    
    }
    (...)
    if (isset($_SESSION['username'])) { // if user is "logged in"
        echo '<h4 id="welcome">welcome &nbsp<a href="#">' . $_SESSION['username'] . '</a></h4>';
    }
    ~ Jeffrey

  • #4
    New Coder
    Join Date
    Apr 2013
    Posts
    11
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Artaex View Post
    Hi,

    Don't put this inside the if-statement where you check for POST variables:
    Code:
    echo "<h4 id='welcome'>welcome &nbsp<a href='#'> $user</a></h4>";
    It will only execute the code above if the form is submitted.
    When you go back to the previous page, the form is not being submitted meaning the code won't show.

    Do something more like this:
    Code:
    if(isset($_POST) && count($_POST)>0) {
    
    }
    (...)
    if (isset($_SESSION['username'])) { // if user is "logged in"
        echo '<h4 id="welcome">welcome &nbsp<a href="#">' . $_SESSION['username'] . '</a></h4>';
    }
    ~ Jeffrey
    it would not worked..
    Last edited by msz900; 09-01-2013 at 06:31 PM.

  • #5
    New Coder
    Join Date
    Dec 2011
    Posts
    80
    Thanks
    5
    Thanked 12 Times in 12 Posts
    I have a utilities.inc.php file that I put the following code in:

    PHP Code:
    session_start();

    // Check for a user in the session:
    $user = (isset($_SESSION['user'])) ? $_SESSION['user'] : NULL
    along with my connection settings and what have you. Though it could go into a connection.php I guess.

    That way all you have to do something like:

    PHP Code:
    $_SESSION['user'] = $row->User_Name
    True courage is about knowing not when to take a life, but when to spare one. PDO Tutorial


  •  

    Tags for this Thread

    Posting Permissions

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