Results 1 to 13 of 13

Thread: [RESOLVED] login problem

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Resolved [RESOLVED] login problem

    hello guys,

    i'm having a problem again with my php code.

    when i login to my site my login box is ment to disappear when i login and show my username and a link to the login page but it isnt doing that it keeps showing the login box can anyone help me please?.

    you can see what i mean if u login using

    mark
    d82f1fc

    when they login it should show this part of the code.

    PHP Code:
    if ($username){
        echo 
    "$username | <a href='logout.php'>Logout</a>";

    if they arent logged in it should show

    PHP Code:
    echo "<form action='login.php' method='post'>
        <center><table>
        <tr>
            <td>Username</td>
            <td><input type='text' name='username' class='textbox' size='35'></td>
            <td><a href='register.php'>Register</a></td>
        </tr>
        <tr>
            <td>Password</td>
            <td><input type='password' name='password' class='textbox' size='35'></td>
            <td><input type='submit' name='loginbtn' value='Login' class='button'></td>
        </tr>
        </table></center>
        </form>"

    This is the full code below.

    PHP Code:
    <?php

    if ($username){
        echo 
    "$username | <a href='logout.php'>Logout</a>";
    }
    else
        echo 
    "<form action='login.php' method='post'>
        <center><table>
        <tr>
            <td>Username</td>
            <td><input type='text' name='username' class='textbox' size='35'></td>
            <td><a href='register.php'>Register</a></td>
        </tr>
        <tr>
            <td>Password</td>
            <td><input type='password' name='password' class='textbox' size='35'></td>
            <td><input type='submit' name='loginbtn' value='Login' class='button'></td>
        </tr>
        </table></center>
        </form>"
    ;

    ?>
    Last edited by Jamie_Garland; Feb 10th, 2013 at 06:26 PM.
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: login problem

    Is that all there is? Where is $username getting set? Presumably login.php checks the user name and password, and the sets a cookie, which should then be used to populate $username...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: login problem

    hello thanks for the reply.

    this is the code for the login.php code.

    PHP Code:
    <?php 
    $title 
    "MBAPPZ.com - Login"?>
    <?php 
    require("styles/top.php"); ?>

        <div id='full'>
        <?php
        
        $form 
    "<form action='login.php' method='post'>
        <center><table>
        <tr>
            <td>Username</td>
            <td><input type='text' name='username'  class='textbox' size='35'></td>
            <td><a href='register.php'>Register</a></td>
        </tr>
        <tr>
            <td>Password</td>
            <td><input type='password' name='password' class='textbox' size='35'></td>
            <td><input type='submit' name='loginbtn' value='Login' class='button'></td>
        </tr>
        </table></center>
        </form>"
    ;
        
        if (
    $_POST['loginbtn']){
            
    $username strip_tags($_POST['username']);
            
    $password strip_tags($_POST['password']);
            
            if (
    $username && $password){
                
                require(
    "scripts/connect.php");
                
                
    $pass md5(md5($password));
                
                
    $query mysql_query("SELECT * FROM users WHERE username='$username' And password='$pass'");
                
    $numrows mysql_num_rows($query);
                
                if (
    $numrows == 1) {
                    
                    
    $row mysql_fetch_assoc($query);
                    
    $dbid $row['id'];
                    
    $dbuser $row['username'];
                    
                    
    $_SESSION['user'] = $dbuser;
                    
    $_SESSION['userid'] = $dbid;
                    
                    echo 
    "<body onload=\"setTimeout('redirect();', 3000);\">";
                    echo 
    "You have been logged in as <b>$dbuser</b>. You will now be redirected to our homepage in a few seconds";
                    
                }
                else
                    echo 
    "Your login information was incorrect. $form";
            }
            else
                echo 
    "You did not fill in the entire form. $form";
        }
        else
            echo 
    "$form";
        
        
    ?>
        </div>
        
    <?php require("styles/bottom.php"); ?>
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: login problem

    OK... so I see you're setting the session object...
    $_SESSION['user'] = $dbuser;
    $_SESSION['userid'] = $dbid;


    But are you reading it back on subsequent pages?

    At the top of each page, you need to read back the session variables to see if you have a User name and User ID... then display (or not) the login form again (or not)...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: login problem

    hello,

    at the top of the top.php page i have

    <?php
    session_start();
    $username = $_SESSION['username'];
    $userid = $_SESSION['userid'];
    ?>
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  6. #6
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: login problem

    Is the re-direct working following a login?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: login problem

    yeah it redirects me to the page but it should show this if logged in

    echo "$username | <a href='logout.php'>Logout</a>";

    and show the form after logout or not logged in?.
    Last edited by Jamie_Garland; Feb 11th, 2013 at 09:06 AM.
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  8. #8
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: login problem

    Ha!... found it....

    When you set the session var.... you used this:
    $_SESSION['user'] = $dbuser;
    $_SESSION['userid'] = $dbid;

    but when you read it back you use this:
    $username = $_SESSION['username'];
    $userid = $_SESSION['userid'];


    See the difference yet?
    $_SESSION['user'] = $dbuser;
    $username = $_SESSION['username'];

    you're writing to one session var, but reading back from another... and so $username is empty and your code thinks the user isn't logged in.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: login problem

    I changed the top to $username = $_SESSION['user'];

    but noe the redirect code isnt working?.
    Last edited by Jamie_Garland; Feb 11th, 2013 at 09:36 AM.
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  10. #10
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: login problem

    Looking at what code you provided for login.php, you didn't call session_start(). You have to call this on every page that you intend to set or retrieve $_SESSION variables.
    Otherwise, if you're getting redirected (meaning your login was successful), $_SESSION['user'] and ['userid'] should work.
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  11. #11
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: login problem

    Quote Originally Posted by MonkOFox View Post
    Looking at what code you provided for login.php, you didn't call session_start(). You have to call this on every page that you intend to set or retrieve $_SESSION variables.
    Otherwise, if you're getting redirected (meaning your login was successful), $_SESSION['user'] and ['userid'] should work.
    I thought the same thing too... but it's in top.php...
    Quote Originally Posted by Jamie_Garland View Post
    hello,

    at the top of the top.php page i have

    <?php
    session_start();
    $username = $_SESSION['username'];
    $userid = $_SESSION['userid'];
    ?>
    if all pages include top.php, then the session should be started, and he's able to read the session data...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  12. #12
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: login problem

    Ah, didn't see that. Hmm, well in that case I'm not really sure what's going on.
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: login problem

    hello,

    i got this part of the code sorted.

    I was wondering is it possible for me if i login to the page with the username Mark it shows a new link saying Add Tutorials but if they arent Mark is dosent show the link can this be done?.

    This is the code i have so far?.

    <?php

    if ($username = 'Mark'){
    echo "<a href='profile.php?id=$userid'>$username</a> | <a href='logout.php'>Logout</a>";
    }
    else
    echo "<form action='login.php' method='post'>
    <center><table>
    <tr>
    <td>Username</td>
    <td><input type='text' name='username' class='textbox' size='25'></td>
    <td><a href='register.php'>Register</a></td>
    </tr>
    <tr>
    <td>Password</td>
    <td><input type='password' name='password' class='textbox' size='25'></td>
    <td><input type='submit' name='loginbtn' value='Login' class='button'></td>
    </tr>
    </table></center>
    </form>";

    ?>
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

Posting Permissions

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



Click Here to Expand Forum to Full Width