Results 1 to 2 of 2

Thread: Login Validator Script Problem

  1. #1
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default Login Validator Script Problem

    Hello everyone, I'm having a bit of a problem with my control panel script... I have the php template from here in this page. The only problem is, that I have it display only when the user is logged in, and even though the inputs are valid, it won't display the menu. If someone could help me that would be a great... thanks...
    PHP Code:
    <?php
    session_start
    ();
    $Username $_SESSION["Username"];
    $Password $_SESSION["Password"];
    ?>
    <?php
        $con 
    mysql_connect("","","");//Input have been removed for privacy
    if (!$con)
      {
      die(
    'Could not connect: ' mysql_error());
      }

    mysql_select_db(""$con);//Inputs have been removed for privacy

    $result mysql_query("SELECT * FROM Users WHERE Username='$username'");

    while(
    $row mysql_fetch_array($result))
      {
       
    $Password $row['Password'];
         if(
    $password==$Password){
                    
    $Logged_in=="true";
                    }
                else{
                    
    $Logged_in=="false";
                }
            
    mysql_query("UPDATE Users SET Status = 'Online' WHERE Username = '$username'");
         }
        
    function 
    validate_login(){
            if(
    $Logged_in=="true"){
            echo 
    generateMenu();
        }
        else{
            echo 
    "Invalid Login";
        }
    }
    ?>
    <?php
    $menu 
    = array();
    $menu['Home'] = 'Home';
    $menu['upload'] = 'Upload a Video';
    $menu['account_options'] = 'Account Options';
    $menu['video_options'] = 'Video Options';
    $menu['Profile'] = 'Profile';
    $menu['Friends'] = 'Friends';
    $menu['Logout'] = 'Logout';
    //Add in the format of: $menu['page name'] = 'Page Title';
    $title='Home'//Default title
    function generateMenu()    {
        global 
    $menu,$default,$title;
        echo 
    '<ul class="solidblockmenu">';
        
    $p = isset($_GET['p']) ? $_GET['p'] : $default;
        foreach (
    $menu as $link=>$item)    {
            
    $class='';
            if (
    $link==$p)    {
                
    $class=' class="selected"';
                
    $title=$item;
            }
            echo 
    '<li><a href="?p='.$link.'"'.$class.'>'.$item.'</a></li>';
        }
        echo 
    '</ul>';
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>

    <style type="text/css">
    h1{
        font-family: Trebuchet Ms;
        font-size: 16px;
        color: #0099FF;
        }
    html,body{
        font-family: Trebuchet Ms;
        font-size: 12px;
    }
    </style>
    <style type="text/css">
    .solidblockmenu{
    margin: 0;
    padding: 0;
    float: left;
    font: bold 13px Arial;
    width: 100%;
    border: 1px solid #0099FF;
    border-width: 1px;
    background: #0099FF url(blockdefault.gif) center center repeat-x;
    }

    .solidblockmenu li{
    display: inline;
    }

    .solidblockmenu li a{
    float: left;
    color: white;
    padding: 9px 11px;
    padding-color: transparent;
    text-decoration: none;
    border-right: 1px solid transparent;
    }

    .solidblockmenu li a:visited{
    color: white;
    }

    .solidblockmenu li a:hover, .solidblockmenu li .current{
    color: white;
    background: transparent url(blockactive.gif) center center repeat-x;
    }
    input{
        background-color: #FFFFFF;
        color: #0099FF;
        border: 1px solid #999999;
        }
    fieldset{
        border: 1px solid #DDDDDD;
        }
    </style>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Pureadd - <?php echo $title?></title>
    </head>

    <body>
    <table align="center" style="border: 2px solid #DDDDDD;" width="645">
    <tr>
    <td colspan="2"><img src="banner.png" /></td>
    </tr>
    <tr>
    <td colspan="2">
    <div class="buttonwrapper"><?php
    echo validate_login();
    $default 'index'//Whatever default page you want to display if the file doesn't exist or you've just arrived to the home page.
    $page = isset($_GET['p']) ? $_GET['p'] : $default//Checks if ?p is set, and puts the page in and if not, it goes to the default page.
    if (!file_exists('inc/'.$page.'.php'))    { //Checks if the file doesn't exist
        
    $page $default//If it doesn't, it'll revert back to the default page
        //NOTE: Alternatively, you can make up a 404 page, and replace $default with whatever the page name is. Make sure it's still in the inc/ directory.
    }
    include(
    'inc/'.$page.'.php'); //And now it's on your page!
    ?>
    <br style="clear: left" />
    </div>
    </td>
    </tr>

    </body>
    </html>

  2. #2
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    A couple of minor things that I found. . .
    PHP Code:
    $result mysql_query("SELECT * FROM Users WHERE Username='$username'");

    while(
    $row mysql_fetch_array($result))
      {
       
    $Password $row['Password'];
         if(
    $password==$Password){
                    
    $Logged_in=="true";
                    }
                else{
                    
    $Logged_in=="false";
                }
            
    mysql_query("UPDATE Users SET Status = 'Online' WHERE Username = '$username'");
         } 
    Can't you just use
    PHP Code:
    $result mysql_query("SELECT * FROM Users WHERE Username='$username' && password ='$password'");
    if(
    MySQL_Num_Rows($result) == 1){
        
    $Logged_in=="true";
        
    mysql_query("UPDATE Users SET Status = 'Online' WHERE Username = '$username'");
        
    /** why was this update outside of the if/else in yours? **/
    }else{
        
    $Logged_in=="false";

    In effect, isn't it the same thing, but with MySQL doing the work rather then PHP? But that's nit-picky. Don't worry about that if it works.

    And, this funtion:
    PHP Code:
    function validate_login(){
        if(
    $Logged_in=="true"){
            echo 
    generateMenu();
        }
        else{
            echo 
    "Invalid Login";
        }

    prints the output, so why does the script echo the call?
    PHP Code:
    echo validate_login(); 
    It doesn't return anything. And where do you pass in the value for $Logged_in?


    Do you know if it's the login or the menu function that is the problem? That would make the problem a little easier to spot.
    Hope this helps a little.
    Last edited by Jas; 02-01-2008 at 07:59 PM.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

Bookmarks

Posting Permissions

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